A

Admin • 832.27K Points
Coach

Q. Which method will throw if there is no element in the stream?

  • (A) findFirst().orElse(null)
  • (B) findFirst().get()
  • (C) findAny().isPresent()
  • (D) findFirst().orElseThrow()

Explanation by: Admin

Calling `get()` on an empty Optional will throw NoSuchElementException.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.