Examveda

What will be the output of the following Java program?
import java.util.*;
class Collection_iterators 
{
    public static void main(String args[]) 
    {
        LinkedList list = new LinkedList();
        list.add(new Integer(2));
        list.add(new Integer(8));
        list.add(new Integer(5));
        list.add(new Integer(1));
        Iterator i = list.iterator();
        Collections.reverse(list);
  Collections.shuffle(list);
        i.next();
        i.remove();
        while(i.hasNext())
      System.out.print(i.next() + " ");
    }
}

A. 2 8 5

B. 2 1 8

C. 2 5 8

D. 8 5 1

Answer: Option B


This Question Belongs to Java Program >> Collections Framework In Java

Join The Discussion

Comments (1)

  1. Ganesh Commn
    Ganesh Commn:
    2 months ago

    Numbers will be printed in random. No specific order

Related Questions on Collections Framework in java