← All Exercises
Optional Chaining Methods
basicjava
Background
Optional provides a type-safe alternative to null checks in modern Java.
Problem
Chain Optional operations to safely navigate nested object properties without NullPointerException.
Input
An Optional wrapping a value
Output
Safely transformed value or default
Sample tests
Sample 1
Input: Optional.of("hello").map(String::length)Expected: Optional[5]
Your solution
Learning objective
Learn null-safe programming with Optional