Matching Operations in Stream.
In this lesson, we will explore the matching operations in Stream.
We'll cover the following...
We'll cover the following...
Matching operations are terminal operations that are used to check if elements with certain criteria are present in the stream or not.
There are mainly three matching functions available in Stream. These are:
anyMatch()allMatch()noneMatch()
We will discuss each one of them with examples.
1) anyMatch()
Here is the syntax of this method:
boolean anyMatch(Predicate<? super T> predicate)
It takes a predicate as input and returns
-
trueif at least one element matches the criteria. -
falseif no element matches the criteria. -
falseif the stream is empty.
In the below example, we have a List of Person objects. We need to check if there is any person residing in a particular country.