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

How to create an interface?

0 Answers  


when i write string s1="java"; in one program(application) and string s2="java"; in another application on the same jvm will both objects s2,s2 will refer to same memory location where "java" is stored in string pool.

2 Answers  


What are 4 pillers of object orinted programming?

0 Answers  


Can we declare a class as abstract without having any abstract method?

0 Answers  


Is 64bit faster than 32 bit?

0 Answers  






can u override the start() method of Thread class

5 Answers  


Name the class that used to read objects directly from a stream?

4 Answers   Wipro,


Write a program to check for a prime number in java?

0 Answers   Cyient,


how to print hello world every second till i have pressed enter key ???

1 Answers   SAP Labs,


What is a boolean flag in java?

0 Answers  


What is collection class in java?

0 Answers  


What are parsing rules?

0 Answers  


Categories