View convert-optional-to-stream.out
jshell> Optional.of("something").stream().forEach(System.out::println)
something
jshell> Optional.empty().stream().forEach(System.out::println)
View use-optional-or.out
jshell> Optional.of("something").or(() -> Optional.of("empty"))
$9 ==> Optional[something]
jshell> Optional.empty().or(() -> Optional.of("empty"))
$10 ==> Optional[empty]
View use-optional-or-else-get.out
jshell> Optional.of("something").orElseGet(() -> "empty")
$7 ==> "something"
jshell> Optional.empty().orElseGet(() -> "empty")
$8 ==> "empty"
View use-optional-or-else.out
jshell> Optional.of("something").orElse("empty")
$5 ==> "something"
jshell> Optional.empty().orElse("empty")
$6 ==> "empty"
View use-optional-if-present-or-else.out
jshell> Optional.empty().ifPresentOrElse(System.out::println, () -> System.out.println("empty"))
empty
jshell> Optional.of("something").ifPresentOrElse(System.out::println, () -> System.out.println("empty"))
something
View use-optional-if-present.out
jshell> Optional.empty().ifPresent(System.out::println)
jshell> Optional.of("something").ifPresent(System.out::println)
something
View complete-optional-api.out
jshell> Optional.of("something").
equals( filter( flatMap( get() getClass()
hashCode() ifPresent( ifPresentOrElse( isPresent() map(
notify() notifyAll() or( orElse( orElseGet(
orElseThrow( stream() toString() wait(
View use-optional-is-present.out
jshell> Optional.empty().isPresent()
$3 ==> false
jshell> Optional.of("something").isPresent()
$4 ==> true
View create-optional-of-something.out
jshell> Optional.of("something")
$2 ==> Optional[something]
View create-empty-optional.out
jshell> Optional.empty()
$1 ==> Optional.empty