JavaIntermediate#java8

What is Optional?

A container introduced in Java 8 to represent possibly-absent values, avoiding NullPointerExceptions. Provides methods like isPresent, ifPresent, orElse, map, flatMap.

Example
Optional<String> name = Optional.ofNullable(getName());
String result = name.map(String::toUpperCase).orElse("UNKNOWN");

Related Questions

1
JavaIntermediate#concurrency

Explain multithreading and the Thread lifecycle.

Open
2
JavaAdvanced#concurrency

Difference between synchronized and volatile?

Open
3
JavaAdvanced#concurrency

What is the Executor framework?

Open