← Quiz: Java Optional: all 10 questions
Quiz: Java Optional · Question 9 of 10
What does Optional.empty().orElseThrow() do?
What does Optional.empty().orElseThrow() do?
- A.Returns null
- B.Returns an empty string
- C.Throws NoSuchElementException
- D.Throws NullPointerException
Answer & explanation
Correct answer: Throws NoSuchElementException
With no argument, orElseThrow throws NoSuchElementException when the Optional is empty.
Can you get the rest right without peeking?
Take the timed Quiz: Java Optional quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →