OptionaloptionalValue = Optional.of("Hello World");
OptionaloptionalValue = Optional.empty();
OptionaloptionalValue = Optional.of("Hello World"); if(optionalValue.isPresent()){ // Code to execute if optionalValue contains a value }
OptionaloptionalValue = Optional.of("Hello World"); String value = optionalValue.get();
OptionalThe package library for java.util.Optional is "java.util". It was introduced in Java 8.optionalValue = Optional.empty(); String value = optionalValue.orElse("Default Value");