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

Collections.reverse(list) reverses the given list, the list was 22->28->25->21 after reversing it became 21->25->28->22.



Your comments will be displayed only after manual approval.