R

Ram Sharma • 3.40K Points
Extraordinary

Q. What will `stream.findFirst().get()` do if stream is empty?

  • (A) Return null
  • (B) Throw NoSuchElementException
  • (C) Return Optional.empty()
  • (D) Return false
  • Correct Answer - Option(B)
  • Views: 9
  • Filed under category Java
  • Hashtags:

Explanation by: Ram Sharma
`Optional.get()` will throw NoSuchElementException if the value is not present.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.