Suppose there is an array list [10,5,20,19,15,24].Print them
in ascending & descending order in collection framework
concept ???

Answers were Sorted based on User's Feedback



Suppose there is an array list [10,5,20,19,15,24].Print them in ascending & descending order in..

Answer / abzy wabzy

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MainClass {
public static void main(String[] a) {
List list = new ArrayList();
list.add("A");
list.add("C");
list.add("B");
Collections.sort(list);//for Ascending order
System.out.println(list);
Collections.sort(list, Collections.reverseOrder
());//for descending order
System.out.println(list);
}
}

Is This Answer Correct ?    5 Yes 0 No

Suppose there is an array list [10,5,20,19,15,24].Print them in ascending & descending order in..

Answer / sagar

Use
Collections.sort(arraylist)

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What state is a thread in when it is executing?

0 Answers  


How to change value in arraylist java?

0 Answers  


explain the concept of virtual method invocation in polymorphism in detail?

0 Answers   TCS,


How to make class immutable

6 Answers  


Can list contain null in java?

0 Answers  






Where to store local variables?

0 Answers   Aspiring Minds,


Can substring create new object?

0 Answers  


Why is core java important?

0 Answers  


Are functions objects in java?

0 Answers  


Why multiple inheritance is not supported by java?

0 Answers  


What is a java lambda expression?

0 Answers  


Which non-unicode letter characters may be used as the first character of an identifier?

0 Answers  


Categories