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 data type in java?
Is an empty arraylist null?
What is the difference between static and global variables and also define what are volatile variables?
0 Answers Flextronics, Hexaware,
what is the difference between String s="hello"; and String s=new String("hello");?
What restrictions are placed on method overriding in java programming?
what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer
What is finally and finalize in java?
What is substring 1 in java?
Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?
what is difference between colection and collections?
25 Answers Amdocs, IBM, Infosys, Ipog Software, Polaris, Tech Mahindra,
Can we overload final method in java?
What is the difference between class & structure?