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

Collections.sort(listobject) sorts the given list, the listobject was 10->9->6->11 after sorting it became 6->9->10->11.



Your comments will be displayed only after manual approval.