Is there is any difference in performance or anything else if I do
list.stream().noneMatch(...)
!list.stream().anyMatch(...)
Both noneMatch
and anyMatch
are short-circuiting stream operations. That means that they will stop processing their input when the result becomes known.
In your case, they will each stop when they do find a match to the Predicate that is passed in. The only difference is that noneMatch
will return false
on a match and anyMatch
will return true
. Your negating the result from anyMatch
makes the two expressions logically equivalent.
Assuming the same list
and the same Predicate
, any performance difference would be negligible. Both methods will short-circuit on the first match, if any, working through the entire list if none actually match, and one negation operator won't make a difference either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With