πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (A) {4=1, 3=1, 2=1}

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

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