πŸ“Š JAVA
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<Integer> treeSet=new TreeSet(new Comparator<Integer>()
{
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]
πŸ’¬ Discuss
βœ… Correct Answer: (B) Compile time exception

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
185
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Pradeep Sikarwar
Publisher
πŸ“ˆ
82%
Success Rate