Run code only if there is a value present

suggest change
Optional<String> optionalWithValue = Optional.of("foo");
optionalWithValue.ifPresent(System.out::println);//Prints "foo".

Optional<String> emptyOptional = Optional.empty();
emptyOptional.ifPresent(System.out::println);//Does nothing.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents