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

What are the disadvantages of object oriented programming?

585


Does java support multiple inheritances?

554


Can we declare register variable as global?

503


How is a structure different from array ?

572


Discuss different types of errors that generally occur while programming.

570






What is bytecode verifier?

493


Explain the importance of finally over return statement?

600


What is the difference between access specifiers and access modifiers in java? 16

532


What are new features introduced with java 8 ?

545


What is a lock or purpose of locks in java?

581


what do you mean by classloader in java?

564


Does every java program need a main?

530


What does flagged out mean?

562


What is the difference between preemptive scheduling and time slicing?

581


What are the advantages of java inner classes?

550