Java: the optional class

Example:

Optional optional = Optional.of("bam");
Optional is a container object which may or may not contain a non-null value.

Solution:

optional.isPresent();           // true
optional.get();                 // "bam"
optional.orElse("fallback");    // "bam"

Beginner's Guide to Java