R

Ram Sharma • 3.40K Points
Extraordinary

Q. What happens if `collect(Collectors.toMap())` encounters duplicate keys?

  • (A) It merges the values automatically
  • (B) It skips duplicates
  • (C) It throws IllegalStateException
  • (D) It returns empty map
  • Correct Answer - Option(C)
  • Views: 2
  • Filed under category Java
  • Hashtags:

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.