Java 8 Stream - anyMatch Example
- schick09
- May 21, 2024
- 1 min read
We've talked about using java.util.stream.forEach in prior posts. Today we're going to talk about the anyMatch feature of the java.util.stream package.
The anyMatch feature takes a Predicate (which evaluates to a boolean) and applies it to all of the elements of the stream. If the Predicate evaluates to 'true', then you can specify subsequent code to execute.
So think of it as saying, "If any of the elements in this collection (stream) meet this criteria, then continue to execute the subsequent code block".
For your reference, we have created an anyMatch example you can take a look at here -- https://github.com/daveschickconsulting/java_8_examples/blob/main/src/funwithjava8streams/MainExample_anyMatch.java

Comments