There's nothing wrong with explicate null-check. If we apply it inside the flatMap()
operation a non-null list step.getJump()
should spawn a stream, otherwise an empty stream needs to be provided:
myList.getJumps().stream()
.flatMap(step -> step.getJump() != null ?
jump.getValue().stream() : Stream.empty())
.collect(Collectors.toList());
Starting with Java 9 we can utilize Stream.ofNullable()
that creates either a singleton stream or an empty stream:
myList.getJumps().stream()
.flatMap(step -> Stream.ofNullable(step.getJump())
.flatMap(jump -> jump.getValue().stream())
.collect(Collectors.toList());