Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 16

Given the code fragment:

Map books = new TreeMap<>();

books.put (1007, "A");

books.put (1002, "C");

books.put (1001, "B");

books.put (1003, "B");

System.out.println (books);

What is the result?

    Correct Answer: B

    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}.

Discussion
Svetleto13Option: B

B,tested.

asdfjhfgjuaDCVOption: B

B is the correct answer

steefaandOption: B

TreeMap sorts keys in ascending order by default so answer is B.

iSnoverOption: 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.

r1muka5Option: B

Correct anwser is B

kishanraoOption: B

the Ans:B

YasinGaberOption: B

B, tested.