Suppose there is an array list [10,5,20,19,15,24].Print them
in ascending & descending order in collection framework
concept ???

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Should you use singleton pattern?

534


What is a method type?

547


Is oracle java 11 free?

535


how to open and edit XML file in Weblogic???

1563


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

617






What is getkey () in java?

588


Explain what access modifiers can be used for methods?

580


Tell me are there implementations for sorting and searching in the java libarary?

612


What do you mean by constant time complexity?

608


What are 3 data types?

554


Explain about member inner classes?

603


Explain a few methods of overloading best practices in java?

521


What is the SimpleTimeZone class?

1807


What is a double?

599


What is passed by reference and pass by value ?

593