I'am trying to filter java collection like this:
filtered = products.stream()
.filter((product) ->size!=null&&
product.getSize().equalsIgnoreCase(size))
.filter((product) ->firmness!=null &&
product.getFirmness().equalsIgnoreCase(firmness))
.collect(Collectors.toList());
In this example i have two variables to filter - size & firmness. This variables are optional and may be nulls. So if i send two not null parameters the code is working and filter fine, but when i send only one parameter and set other parameter to null - it's not working. I need my collection to get filtered by not null values. So if one parameter is null, other is not, the collection must to get filtered by not null value. How i can did this ?