If you use Eclipse Collections, there is indeed a third way to approach your specific example.you can use the Eclipse Collections' collectIf()
method allows a single callmethod to deal with both filteringfilter and transformationtransform at the same time.
myFinalList = myListToParse.collectIf(
Objects::nonNull,
elt -> doSomething(elt));
It evaluates eagerly and should be a bit faster than using a Stream
.
EC's Collect pattern is documented in its reference guide.
Note: I am a committer for Eclipse Collections.