How to replace a value conditionally in a Collection, such as replaceIf(Predicate<T>)?

Viewed 12539

Is there any easy way we could replace a value in a List or Collection if the value is null?

We can always do list.stream().filter(Objects::nonNull); and maybe add 0 back to the list.

But what I am looking for is an API like list.replaceIf(Predicate<>).

4 Answers
Related