WEBVTT

00:00.700 --> 00:01.270
Hi everyone.

00:01.270 --> 00:02.620
Welcome back to this tutorial.

00:02.620 --> 00:09.400
In this tutorial we will code and learn about the match all match and non match stream function.

00:10.530 --> 00:11.640
This any match?

00:11.670 --> 00:13.260
All match and none match.

00:13.290 --> 00:18.480
Dixon a predicate as an input and returns the boolean as an output.

00:18.510 --> 00:25.170
We can use all of these functions in scenarios where you want to find whether a particular element is

00:25.170 --> 00:29.550
present in the stream or not present in the stream or not.

00:31.880 --> 00:37.220
Any match returns true if any one of the element matches the predicate.

00:37.250 --> 00:39.800
Otherwise it's going to return false.

00:40.660 --> 00:41.740
All match returns.

00:41.740 --> 00:46.030
True if the all the elements in the stream matches the predicate.

00:46.060 --> 00:48.910
Otherwise it is going to return false.

00:49.030 --> 00:50.050
The none match.

00:50.080 --> 00:53.170
It is just opposite to all match returns.

00:53.170 --> 00:57.460
True, if none of the elements in the stream matches the predicate.

00:57.490 --> 01:00.490
Otherwise this is going to return false.

01:00.520 --> 01:02.080
Let's go ahead and code this one.

01:04.220 --> 01:06.500
I have the IntelliJ idea open in here.

01:06.500 --> 01:09.980
What I'm going to do, I'm going to create a class called.

01:11.760 --> 01:12.510
Dreams.

01:13.710 --> 01:15.240
Match example.

01:17.060 --> 01:20.990
And then I'm going to make this class executable by adding public static void main.

01:22.380 --> 01:23.280
The next purpose.

01:24.940 --> 01:26.560
And to put this in presentation mode.

01:27.980 --> 01:34.820
Let's explore the all match method first, meaning all match function, which is part of the streams

01:34.850 --> 01:35.570
API.

01:36.770 --> 01:39.500
The name of the method is going to be public static.

01:41.020 --> 01:41.890
Boolean.

01:43.230 --> 01:46.170
All match is a name which I'm going to give for this method.

01:47.230 --> 01:47.920
The first purpose.

01:47.920 --> 01:48.420
I'm gonna.

01:49.900 --> 01:53.080
All the student database and get all the students.

01:53.820 --> 01:55.830
And call the stream method.

01:57.000 --> 02:00.920
So we are going to explore the all match function.

02:00.930 --> 02:02.760
Just part of the streams API, right?

02:03.740 --> 02:06.260
If all match, we take a look at it all.

02:06.260 --> 02:08.900
Match takes in an input as an predicate.

02:09.670 --> 02:10.200
Okay.

02:10.210 --> 02:18.520
The predicate which I'm going to give is going to be student dot three, student dot get GPA.

02:20.830 --> 02:24.520
Is greater than or equal to 3.9.

02:26.010 --> 02:26.520
Right.

02:26.520 --> 02:35.550
So what this is going to do, this is going to check whether all the students in this stream has a GPA

02:35.580 --> 02:37.260
greater than or equal to 3.9.

02:37.260 --> 02:38.670
Let's go ahead and check this.

02:38.970 --> 02:45.480
If you take a look at it, only there are two students who has a GPA, sorry, three students who has

02:45.480 --> 02:47.850
a GPA greater than or equal to 3.9.

02:47.880 --> 02:51.780
What I'm going to do is I'm going to go back and then.

02:52.800 --> 02:53.730
All this method.

02:54.720 --> 02:55.800
And check the result.

02:56.620 --> 03:03.060
So I'm going to put into sort going to be result of all match.

03:05.260 --> 03:06.340
Check the result.

03:06.370 --> 03:07.780
Call the all match.

03:08.770 --> 03:11.020
And run this example.

03:12.330 --> 03:19.570
This is going to return false because in the students object in the get all students method, it returns

03:19.680 --> 03:21.030
returns a list of students.

03:21.060 --> 03:25.640
Not all the students has the GPA as 3.9.

03:25.650 --> 03:27.000
What is the least GPA?

03:27.030 --> 03:29.220
The least GPA is 3.5.

03:29.250 --> 03:34.140
What I'm going to do, I'm going to change this condition to 3.5.

03:34.350 --> 03:39.090
Now, all the students in the stream matches this condition.

03:39.450 --> 03:42.720
So it is going to return true as a result.

03:42.720 --> 03:45.480
As you see, the result is returned as true.

03:45.780 --> 03:47.910
So this is all about all match.

03:47.910 --> 03:50.280
Let's go ahead and explore the next.

03:51.730 --> 03:53.530
Function, which is any match.

03:54.310 --> 03:55.780
Want to just copy this?

03:56.980 --> 04:00.100
And change a method name to any match.

04:00.190 --> 04:03.010
And in here we have to use any match.

04:03.100 --> 04:08.050
Here, what I'm going to do, I'm going to give the value as 4.0.

04:08.710 --> 04:13.810
Basically, what this is going to do, this is going to check whether any of the students in this list

04:13.840 --> 04:16.900
has the GPA as 4.0.

04:18.240 --> 04:21.660
So we have only one students who has the GPA as 4.0.

04:22.770 --> 04:30.870
This is going to return false because it matches the required criteria that any one of the student matches

04:30.870 --> 04:31.920
the condition.

04:33.130 --> 04:35.240
Basically matches a predicate runner.

04:35.290 --> 04:39.040
This is also going to return the result as true.

04:39.970 --> 04:41.710
Now I'm going to make it fail.

04:41.710 --> 04:46.210
I'm going to give the value as 4.1 as 4.0 is a.

04:49.140 --> 04:50.370
GPA's student can have.

04:50.370 --> 04:50.730
I'm going to.

04:50.820 --> 04:58.050
I'm changing the condition to 4.04.1 so that it can fail and return the value as false.

04:58.080 --> 04:58.620
There you go.

04:58.650 --> 05:00.660
It returned the value as false.

05:00.930 --> 05:03.030
I'm going to change it back to its original value.

05:03.330 --> 05:06.030
Now let's go ahead and explore the Non-match.

05:08.570 --> 05:09.740
The non-match.

05:14.590 --> 05:14.950
Here.

05:14.950 --> 05:16.300
I'm going to use Non-match.

05:16.330 --> 05:20.290
Non-match is just the opposite of all match.

05:21.080 --> 05:25.910
None of the if none of the students matches this criteria, this is going to return true.

05:26.570 --> 05:33.770
In order to make that happen, what I'm going to give, I'm going to give an invalid GPA which is not

05:33.770 --> 05:37.940
present in any which which the value is not present for any of the students.

05:37.940 --> 05:42.080
So none of the students has the GPA or the GPA has 4.1.

05:42.080 --> 05:44.120
Now this is going to return.

05:44.150 --> 05:44.840
True.

05:46.670 --> 05:48.200
I change this one to Non-match?

05:49.370 --> 05:51.170
Make the call to Non-match.

05:51.200 --> 05:55.220
Now, if I run it, this is going to return true, because.

05:57.110 --> 05:59.870
None of the students has a GPA has 4.1.

05:59.900 --> 06:00.480
There you go.

06:00.500 --> 06:07.580
If I change this one, this value to 4.0 because we have one student who has a GPA as 4.0.

06:07.700 --> 06:12.620
So this condition is going to fail and then return the result as false.

06:13.130 --> 06:13.690
Here we go.

06:13.700 --> 06:17.240
The the result is returned as false.

06:17.600 --> 06:21.470
So this is all about all match any match and none match.

06:21.470 --> 06:23.780
But this we came to the end of this tutorial.

06:23.810 --> 06:25.010
Thank you for watching.
