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?
The code initializes a TreeMap, which stores its keys in natural (ascending) order. The entries are added according to their keys: 1007, 1002, 1001, and 1003. When printed, the map will order its keys as {1001=B, 1002=C, 1003=B, 1007=A}.
Correct answer is B {1001=B, 1002=C, 1003=B, 1007=A}
B is correct.