Matching Operations in Stream.

In this lesson, we will explore the matching operations in Stream.

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

  • true if at least one element matches the criteria.

  • false if no element matches the criteria.

  • false if 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.

Get hands-on with 1400+ tech skills courses.