Your code essentially goes through the input lines, executes doSomthingfor each of them ( mapin Java terminology), ignores the results null( filterin Java terminology), and then produces a list of these results ( collectin Java terminology). And when you are all together:
List<SomeClass> outputResultStrings =
inputStrings.stream()
.map(SomeClass::doSomething)
.filter(x -> x != null)
.collect(Collectors.toList());
EDIT:
As suggested by Tunaki, a non-null check can be cleared with Objects::nonNull:
List<SomeClass> outputResultStrings =
inputStrings.stream()
.map(SomeClass::doSomething)
.filter(Objects::nonNull)
.collect(Collectors.toList());
source
share