← All topics
Quiz: Java Optional: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What does this print? (code)
- Q2. What happens with Optional.of(null)?
- Q3. What is the difference between orElse(x()) and orElseGet(() - x())?
- Q4. What does this print? (code)
- Q5. When should you use flatMap instead of map on an Optional?
- Q6. Which is a recommended use of Optional?
- Q7. What does this print? (code)
- Q8. Which stream operation returns an Optional?
- Q9. What does Optional.empty().orElseThrow() do?
- Q10. A method returns Optional<Student. Which return statement is WRONG when nothing is found?