P

Pradeep Sikarwar • 9.01K Points
Tutor III

Q. What will be the output of the following code

Code:
import java.util.Comparator;

public class SortSet {
public static void main(String…a)
{
Set treeSet=new TreeSet(new Comparator()
{
public int compareTo(Integer o1,Integer o2)
{
return o2.compareTo(o1);
}
});
treeSet.add(3);
treeSet.add(1);
treeSet.add(2);
System.out.println(treeSet);

}

}
  • (A) [3, 2, 1]
  • (B) Compile time exception
  • (C) Runtime exception
  • (D) [1, 2, 3]
  • Correct Answer - Option(B)
  • Views: 116
  • Filed under category JAVA

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.


Question analytics