Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about the relationship between a map and the set returned by keySet is true?

  • A.The set is a view.
  • B.The set is a copy, so removing a key from it leaves the map unchanged.
  • C.The set is a view, but it is unmodifiable and rejects removal.
  • D.The set is a copy that is refreshed each time the map changes.

Answer: A

keySet, values and entrySet are all views onto the same data, so removals write through to the map, and changes to the map appear in the view. What they do not support is adding, since a key alone would not be a complete entry.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.