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

Discussion

Which of these statements about what Map.Entry.setValue does is correct?

  • A.It changes only the entry object.
  • B.It throws UnsupportedOperationException.
  • C.It inserts a new entry.
  • D.It writes the new value through to the map the entry came from.

Answer: D

Correct answer: It writes the new value through to the map the entry came from.

A Map.Entry obtained from entrySet() is a view onto the map, so setValue updates the mapping itself - which is the supported way of modifying values while iterating a map. The entry is valid only for the duration of the iteration, and its behaviour afterwards is undefined; an unmodifiable map is the case that throws UnsupportedOperationException.

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

Post your comment

Please log in or register to post a comment.