P
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);
}
}
public class SortSet {
public static void main(String…a)
{
Set
{
public int compareTo(Integer o1,Integer o2)
{
return o2.compareTo(o1);
}
});
treeSet.add(3);
treeSet.add(1);
treeSet.add(2);
System.out.println(treeSet);
}
}
- Correct Answer - Option(B)
- Views: 116
- Filed under category JAVA
Discusssion
Login to discuss.