Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove "null" values from a Java Stream [duplicate]

Let's say I have a Java Stream that contains null values.

How do you remove them ?

like image 829
Chris Avatar asked Aug 24 '26 14:08

Chris


1 Answers

Here's a few ways I can think of:

stream.filter(x -> x != null).

stream.filter(Objects::nonNull)

like image 99
Chris Avatar answered Aug 27 '26 04:08

Chris