Home » JAVA Programming » Collections » Question
  1. What is the output of this program?
    import java.util.*;
    public class Collection_AlgosExample
    {
    public static void main(String args[])
    {
    LinkedList listobject = new LinkedList();
    listobject.add(new Integer(13));
    listobject.add(new Integer(23));
    listobject.add(new Integer(3));
    listobject.add(new Integer(11));
    Iterator Itr = listobject.iterator();
    Collections.reverse(listobject);
    Collections.sort(listobject);
    while(Itr.hasNext())
    System.out.print(Itr.next() + " ");
    }
    }
    1. 3 11 13 23
    2. 13 23 3 11
    3. 3 11 13
    4. 13 11 3
    5. 23 13 11 3
Correct Option: A

Collections.sort(list) sorts the given list, the list was 13->23->3->11 after sorting it became 3->11->13->23.



Your comments will be displayed only after manual approval.