Run code only if there is a value present
suggest changeOptional<String> optionalWithValue = Optional.of("foo");
optionalWithValue.ifPresent(System.out::println);//Prints "foo".
Optional<String> emptyOptional = Optional.empty();
emptyOptional.ifPresent(System.out::println);//Does nothing.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents