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
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 |
What state is a thread in when it is executing?
How to change value in arraylist java?
explain the concept of virtual method invocation in polymorphism in detail?
How to make class immutable
Can list contain null in java?
Where to store local variables?
Can substring create new object?
Why is core java important?
Are functions objects in java?
Why multiple inheritance is not supported by java?
What is a java lambda expression?
Which non-unicode letter characters may be used as the first character of an identifier?