Question 13
Back to Exercise
What happens at int n = map.get("missing"); when the key is absent (map is a Map<String, Integer>)?
- A n becomes 0
- B NullPointerException – get returns null, which cannot be unboxed Correct
- C Compile error
- D n becomes -1
Correct Answer: Option B
Use getOrDefault("missing", 0).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!