P

Pradeep Sikarwar • 9.01K Points
Tutor III

Q. What will be the output of the following code

Code:
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
public class SortMap {

public static void main(String…a)
{
Map<Integer,Integer> treeMap = new TreeMap<Integer,Integer>(new Comparator<Integer>()
{
public int compare(Integer o1,Integer o2)
{
return o2.compareTo(o1);
}
});
treeMap.put(4,1);
treeMap.put(2,1);
treeMap.put(3,1);{

System.out.println(treeMap);

}
}
}
  • (A) {4=1, 3=1, 2=1}
  • (B) {2=1, 3=1, 4=1}
  • (C) {4=1, 2=1, 3=1}
  • (D) Compile time exception

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.