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 |
Can we use string in switch case in java?
What is empty list in java?
What is the purpose of garbage collection in java?
Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?
What is the purpose of lambda expressions?
What does || || mean in math?
What is return keyword in java?
What are the important features of Java 8 release?
What is a variable in java?
What is the difference between state-based unit testing and interaction-based unit testing?
What is equlas() and hashcode() contract in java? Where does it used?
What is r in java?