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);
	    Collections.sort(list);
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }

a.

2 8 5 1

b.

1 5 8 2

c.

1 2 5 8

d.

2 1 8 5

Posted under Java Programming

Answer: (c).1 2 5 8

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 these is true about unmodifiableCollection() method?

Q. Which of these methods can convert an object into a List?

Q. Which of these methods can randomize all elements in a list?

Q. Which of these methods sets every element of a List to a specified object?

Q. Which of these is an incorrect form of using method max() to obtain a maximum element?

Q. What is Collection in Java?

Q. Which of these methods deletes all the elements from invoking collection?

Q. Which of this interface is not a part of Java’s collection framework?

Q. Which of these classes is not part of Java’s collection framework?

Q. Which of these packages contain all the collection classes?

Q. Which of these package provides the ability to read and write in Zip format?

Q. Which of these interfaces is implemented by TimerTask class?

Q. Which of these classes can schedule task for execution in future?

Q. Which of these methods is called when observed object has changed?

Q. Which of these methods calls update() method?

Q. Which of these methods is used to notify observer the change in observed object?

Q. What is the use of Observable class?

Q. Which of these is a method can generate a boolean output?

Q. Which of these method of Locale class can be used to obtain country of operation?

Q. Which of these class can generate pseudorandom numbers?