I have a list of predicates (List<Predicate<String>>
) which I want to chain into one using or
methods. How can I use the Stream API to achieve that?
You can use reduce
to join them all together with or
, yielding a single Predicate<String>
. Like this:
List<Predicate<String>> predicates = getPredicates();
Predicate<String> p = predicates.stream()
.reduce(s -> false, Predicate::or);