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

Should a main method be compulsorily declared in all java classes?

0 Answers  


how and when compiler knows that the Java code throws the checked Exception.

2 Answers   HSBC,


How do you sing an Applet ?

0 Answers  


What is the difference between declaration and definition in java?

0 Answers  


When the constructor of a class is invoked?

0 Answers  






Why bytecode is called bytecode?

0 Answers  


Can we force the garbage collection to run?

0 Answers  


can we write a program with out a class in core java?

11 Answers   Wipro,


If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?

0 Answers  


How to perform linear search in java?

0 Answers  


What does string [] args mean?

0 Answers  


23. Storage space in java is of the form Stack Queue Heap List 24. What is java code embedded in a web page known as Applets Servlets scriptlets snippets 25. Which of the following attributes are compulsory with an <applet> tag?. code,height & width. 26. What does 'CODEBASE' in an applet tag specify?. Files absolute path.

0 Answers   TCS,


Categories