I want to filter a java.util.Collection
based on a predicate.
Since java 9 Collectors.filtering
is enabled:
public static
Collector filtering(Predicate super T> predicate,
Collector super T, A, R> downstream)
Thus filtering should be:
collection.stream().collect(Collectors.filtering(predicate, collector))
Example:
List oddNumbers = List.of(1, 19, 15, 10, -10).stream()
.collect(Collectors.filtering(i -> i % 2 == 1, Collectors.toList()));