LearnFrenzy
Sign in Take a free test

HashMap and TreeMap · HashMap and TreeMap MCQ · Question 20

The views returned by keySet and values Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

What happens if you remove an element from map.values()?

  • A Nothing – it is a copy
  • B The corresponding entry is removed from the map, because values() is a live view Correct
  • C An exception is always thrown
  • D Only the value becomes null
Correct Answer: Option B

keySet(), values() and entrySet() are views backed by the map.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links