R

Ram Sharma • 3.40K Points
Extraordinary

Q. What happens if duplicate keys are provided in `Collectors.toMap()` without a merge function?

  • (A) Keeps the first key
  • (B) Throws an exception
  • (C) Overrides the previous value
  • (D) Creates a list of values
  • Correct Answer - Option(B)
  • Views: 7
  • Filed under category Java
  • Hashtags:

Explanation by: Ram Sharma
`Collectors.toMap()` throws `IllegalStateException` on duplicate keys unless a merge function is supplied.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.