-
What is the output of this program?
import java.util.*;
public class Collection_iterator_Example
{
public static void main(String args[])
{
LinkedList listobject = new LinkedList();
listobject.add(new Integer(10));
listobject.add(new Integer(3));
listobject.add(new Integer(15));
listobject.add(new Integer(12));
Iterator Itr = listobject.iterator();
Collections.reverse(listobject);
Collections.shuffle(listobject);
Itr.next();
Itr.remove();
while(Itr.hasNext())
System.out.print(Itr.next() + " ");
}
}
-
- 12 10 15
- 10 3 15 12
- 3 15 12 10
- 3 10 12 15
- None of these
Correct Option: A
Itr.next() returns the next element in the iteration. Itr.remove() removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next(). The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.