Given the code fragment:
Map
books.put (1007, "A");
books.put (1002, "C");
books.put (1001, "B");
books.put (1003, "B");
System.out.println (books);
What is the result?
Given the code fragment:
Map
books.put (1007, "A");
books.put (1002, "C");
books.put (1001, "B");
books.put (1003, "B");
System.out.println (books);
What is the result?
TreeMap in Java sorts its entries based on the keys in natural ascending order. Given the keys 1007, 1002, 1001, and 1003, the sorted order will be 1001, 1002, 1003, and 1007, respectively. Therefore, the correct result of printing the TreeMap will be {1001 = B, 1002 = C, 1003 = B, 1007 = A}.
B,tested.
B is the correct answer
TreeMap sorts keys in ascending order by default so answer is B.
Looking at the reference type, it is a TreeMap, so it is ordered using the key, and as the key is of type "int", the correct answer is B.
Correct anwser is B
the Ans:B
B, tested.