Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and learn about the match all match and non match stream function.
This any match?
All match and none match.
Dixon a predicate as an input and returns the boolean as an output.
We can use all of these functions in scenarios where you want to find whether a particular element is
present in the stream or not present in the stream or not.
Any match returns true if any one of the element matches the predicate.
Otherwise it's going to return false.
All match returns.
True if the all the elements in the stream matches the predicate.
Otherwise it is going to return false.
The none match.
It is just opposite to all match returns.
True, if none of the elements in the stream matches the predicate.
Otherwise this is going to return false.
Let's go ahead and code this one.
I have the IntelliJ idea open in here.
What I'm going to do, I'm going to create a class called.
Dreams.
Match example.
And then I'm going to make this class executable by adding public static void main.
The next purpose.
And to put this in presentation mode.
Let's explore the all match method first, meaning all match function, which is part of the streams
API.
The name of the method is going to be public static.
Boolean.
All match is a name which I'm going to give for this method.
The first purpose.
I'm gonna.
All the student database and get all the students.
And call the stream method.
So we are going to explore the all match function.
Just part of the streams API, right?
If all match, we take a look at it all.
Match takes in an input as an predicate.
Okay.
The predicate which I'm going to give is going to be student dot three, student dot get GPA.
Is greater than or equal to 3.9.
Right.
So what this is going to do, this is going to check whether all the students in this stream has a GPA
greater than or equal to 3.9.
Let's go ahead and check this.
If you take a look at it, only there are two students who has a GPA, sorry, three students who has
a GPA greater than or equal to 3.9.
What I'm going to do is I'm going to go back and then.
All this method.
And check the result.
So I'm going to put into sort going to be result of all match.
Check the result.
Call the all match.
And run this example.
This is going to return false because in the students object in the get all students method, it returns
returns a list of students.
Not all the students has the GPA as 3.9.
What is the least GPA?
The least GPA is 3.5.
What I'm going to do, I'm going to change this condition to 3.5.
Now, all the students in the stream matches this condition.
So it is going to return true as a result.
As you see, the result is returned as true.
So this is all about all match.
Let's go ahead and explore the next.
Function, which is any match.
Want to just copy this?
And change a method name to any match.
And in here we have to use any match.
Here, what I'm going to do, I'm going to give the value as 4.0.
Basically, what this is going to do, this is going to check whether any of the students in this list
has the GPA as 4.0.
So we have only one students who has the GPA as 4.0.
This is going to return false because it matches the required criteria that any one of the student matches
the condition.
Basically matches a predicate runner.
This is also going to return the result as true.
Now I'm going to make it fail.
I'm going to give the value as 4.1 as 4.0 is a.
GPA's student can have.
I'm going to.
I'm changing the condition to 4.04.1 so that it can fail and return the value as false.
There you go.
It returned the value as false.
I'm going to change it back to its original value.
Now let's go ahead and explore the Non-match.
The non-match.
Here.
I'm going to use Non-match.
Non-match is just the opposite of all match.
None of the if none of the students matches this criteria, this is going to return true.
In order to make that happen, what I'm going to give, I'm going to give an invalid GPA which is not
present in any which which the value is not present for any of the students.
So none of the students has the GPA or the GPA has 4.1.
Now this is going to return.
True.
I change this one to Non-match?
Make the call to Non-match.
Now, if I run it, this is going to return true, because.
None of the students has a GPA has 4.1.
There you go.
If I change this one, this value to 4.0 because we have one student who has a GPA as 4.0.
So this condition is going to fail and then return the result as false.
Here we go.
The the result is returned as false.
So this is all about all match any match and none match.
But this we came to the end of this tutorial.
Thank you for watching.