Home / Programming MCQs / JAVA MCQs / Question

P

Pradeep Sikarwar • 9.01K Points
Tutor III

Q. What will be the output of the following code

Code:
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class SortSet {
public static void main(String…a)
{
Collection<Integer> collection = new HashSet<Integer>();
collection.add(3);
collection.add(1);
collection.add(2); {

Set<Integer> treeSet=new TreeSet<Integer>(collection);
System.out.println(treeSet);

}
}
}
(A) [1, 2, 3]
(B) Runtime exception
(C) [3, 2, 1]
(D) None of the above

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.