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 is data type in java?

0 Answers  


Is an empty arraylist null?

0 Answers  


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");?

3 Answers  


What restrictions are placed on method overriding in java programming?

0 Answers  






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

4 Answers   IBM, Zenon,


What is finally and finalize in java?

0 Answers  


What is substring 1 in java?

0 Answers  


Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?

1 Answers  


what is difference between colection and collections?

25 Answers   Amdocs, IBM, Infosys, Ipog Software, Polaris, Tech Mahindra,


Can we overload final method in java?

0 Answers  


What is the difference between class & structure?

0 Answers  


Categories