ProgrammingModerateProduct-company placement · Java

What is printed?

What is printed?
Map<String, Integer> m = new LinkedHashMap<>();
m.put("x", 1); m.put("y", 2); m.put("x", 3);
System.out.print(m);
  1. A. {y=2, x=3}
  2. B. {x=3, y=2}
  3. C. {x=1, y=2, x=3}
  4. D. {x=1, y=2}

Correct answer: B. {x=3, y=2}

In the default insertion-order mode, re-inserting an existing key replaces its value but does not change its position.

More OOP with C++ and Java questions

Exams that ask this topic