Return first non-null value
String s = Stream.<Supplier<String>>of(this::first, this::second /*, … */) .map(Supplier::get) .filter(Objects::nonNull) .findFirst() .orElseGet(this::defaultOne); It stops on the first non-null value or else sets the value which is returned from defaultOne. As long as you stay sequential, you are safe. Of course this requires Java 8 or later. The reason why it stops on the first occurrence … Read more