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

Discussion

Consider what Map.forEach receives for each entry. Which statement is correct?

  • A.An index and the entry, as a list's forEach would.
  • B.The key and the value, as the two arguments of a BiConsumer.
  • C.A Map.Entry object, from which the key and value are read.
  • D.The key only, leaving the value to be fetched with get.

Answer: B

It takes a BiConsumer, so the lambda is written with two parameters and no entry object or second lookup is needed. It is the concise equivalent of iterating entrySet, and like that loop it must not modify the map while running.

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

Post your comment

Please log in or register to post a comment.