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 is visibility mode?
What is the reason that multiple inheritance is not possible in java??
what is custom tags with example?
what is unreachable code problem in multiple catch statements
What are the methods available in a class?
Why are lists ordered in java?
Which package is always imported by default?
there are some duplicate values in ArrayList, how U'll get that array with out duplicate?
What is the format of Inner Class after it compiled?
Can we extend private class in java?
What is the difference between throw and throws? What is the similarity between try and throw?
What are methods?