R

Ram Sharma • 3.40K Points
Extraordinary

Q. What happens if you collect a stream into `Collectors.toUnmodifiableSet()` and try to add an element?

  • (A) Set accepts the new element
  • (B) It adds and returns true
  • (C) Throws UnsupportedOperationException
  • (D) Returns null
  • Correct Answer - Option(C)
  • Views: 18
  • Filed under category Java
  • Hashtags:

Explanation by: Ram Sharma

Unmodifiable sets do not allow changes after creation; modifying will throw `UnsupportedOperationException`.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.