As Optional have only ifPresent and not have another function to be run in false case so I did the below class for that, please check it and give me your feedback:public class OptionalConsumer<T> {private Optional<T> optional;private OptionalConsumer(Optional<T> optional) {    this.optional = optional;}public static <T> OptionalConsumer<T> of(Optional<T> optional) {    return new OptionalConsumer<>(optional);}public OptionalConsumer<T> ifPresent(Consumer<T> c) {    optional.ifPresent(c);    return this;}public OptionalConsumer<T> ifNotPresent(Runnable r) {    if (!optional.isPresent())        r.run();    return this;}}Then :Optional<Any> o = Optional.of(...);OptionalConsumer.of(o).ifPresent(s ->System.out.println(isPresent +s))        .ifNotPresent(() -> System.out.println(! isPresent));
Optional Consumer for ifNotPresent
java;functional programming;optional