adplus-dvertising
frame-decoration

Question

What is the output of this 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);
     while(i.hasNext())
         System.out.print(i.next() + " ");
        }
    }

a.

2 8 5 1

b.

1 5 8 2

c.

2

d.

2 1 8 5

Answer: (b).1 5 8 2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. Which of the below is not a subinterface of Queue?

Q. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined?

Q. PriorityQueue is thread safe.

Q. What is difference between dequeue() and peek() function of java?

Q. What is the difference between Queue and Stack?

Q. What are the use of front and rear pointers in CircularQueue implementation?

Q. What is the correct method used to insert and delete items from the queue?

Q. Which data structure is used in Breadth First Traversal of a graph?

Q. Where does a new element be inserted in linked list implementation of a queue?

Q. If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder to insert an element in the queue?

Q. Which of these standard collection classes implements all the standard functions on list data structure?

Q. Which of this method is used to make all elements of an equal to specified value?

Q. Which of these method of Array class is used sort an array or its subset?

Q. Which of these methods can be used to search an element in a list?

Q. Which of these interface declares core method that all collections will have?

Q. Which of these interface handle sequences?

Q. Which of this interface must contain a unique element?

Q. Which of these is a Basic interface that all other interface inherits?

Q. Which of these is static variable defined in Collections?

Q. Which class is used to generate random number?