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

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: D

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

Discussion
ChoucouOption: A

Correct answer is B {1001=B, 1002=C, 1003=B, 1007=A}

steefaandOption: A

B is correct.