DEV Community

Discussion on: Filter Null Values from a List with Java8 Lambda

Collapse
 
pnaranja profile image
Paul

I use streams all the time to filter out results from my collections as well!

I know your title says "Java8", but note that Java 9 has Optional::stream

So now:
.map(this::lookupSettingByName)
.filter(Optional::isPresent)
.map(Optional::get)

Can be transformed to:
.map(this::lookupSettingByName)
.flatMap(Optional::stream)

Here's a reference link - iteratrlearning.com/java9/2016/09/...

Though I understand the filter -> map approach can be more readable

Collapse
 
monknomo profile image
Gunnar Gissel

That's a cool thing, for sure!