Quiz Entry - updated: 2026.12.01
Start with an empty map and run put(5,A), put(7,B), put(2,C), put(8,D), put(2,E), get(7), get(4), remove(5), remove(2). What does each call return, and what is left?
null, null, null, null, C, B, null, A, E; the map ends as {(7,B), (8,D)}.
| Call | Returns | Map afterwards |
|---|---|---|
put(5,A) |
null | {(5,A)} |
put(7,B) |
null | {(5,A),(7,B)} |
put(2,C) |
null | {(5,A),(7,B),(2,C)} |
put(8,D) |
null | {(5,A),(7,B),(2,C),(8,D)} |
put(2,E) |
C | {(5,A),(7,B),(2,E),(8,D)} |
get(7) |
B | unchanged |
get(4) |
null | unchanged |
remove(5) |
A | {(7,B),(2,E),(8,D)} |
remove(2) |
E | {(7,B),(8,D)} |
The interesting line is put(2,E): key 2 already exists, so the map does not grow to five entries. It overwrites C with E and hands C back. After it, size() is 4.
At the end keySet() is {7, 8}, values() is {B, D} and isEmpty() is false.