Optional<T> is a container object that may or may not hold a non-null value—explicitly forcing callers to handle the missing case with orElse(), orElseThrow(), or ifPresent() instead of crashing with a NullPointerException.
ADVERTISEMENT