WEBVTT

00:00.670 --> 00:01.150
Hi everyone.

00:01.150 --> 00:02.410
Welcome back to this tutorial.

00:02.410 --> 00:09.700
In this tutorial we will code and learn how to debug a stream API and what gets passed between the stream

00:09.700 --> 00:10.630
operations.

00:10.660 --> 00:16.750
I'm going to open the example which we coded in one of the previous tutorial, which is streams example.

00:17.140 --> 00:18.100
Let's click on that.

00:18.100 --> 00:26.020
So if you take a look at this example, we are performing one, two and three stream operations and

00:26.020 --> 00:28.390
I'm going to run this example first and check the result.

00:29.350 --> 00:33.370
The result is the name and the students activities.

00:33.370 --> 00:34.820
That's what we are printing here.

00:34.840 --> 00:40.060
Now we want to see what is being parsed from the stream method to the filter method.

00:40.210 --> 00:46.390
There is a handy method that is available as part of the stream API, which is the called peek.

00:47.000 --> 00:51.040
So if you take a look at the peak, peek accepts a consumer.

00:51.130 --> 00:53.770
We all know consumer by now.

00:53.770 --> 00:58.690
Consumer accepts an input and which doesn't return any output.

00:58.810 --> 01:01.360
So now what I'm going to do, I'm going to build a consumer.

01:01.360 --> 01:02.740
Let's create the lambda.

01:03.250 --> 01:07.640
So have the lambda created and it is going to take student as an input.

01:07.660 --> 01:10.840
As soon as I typed in the student, it gave me this recommendation.

01:10.840 --> 01:11.980
I'm going to press enter.

01:12.010 --> 01:12.640
There you go.

01:12.640 --> 01:14.380
We have the lambda created.

01:14.680 --> 01:17.410
To open the curly braces.

01:17.410 --> 01:19.360
And in here, what I'm going to do.

01:19.390 --> 01:20.140
I'm going to.

01:21.470 --> 01:22.220
Rent the student.

01:23.260 --> 01:25.810
For this in presentation mode, the code will be clear.

01:27.550 --> 01:28.030
There you go.

01:28.030 --> 01:35.410
So we have this pick method and then we have the consumer parsed as part of the pick method, as an

01:35.410 --> 01:37.090
input to the pick method actually.

01:37.090 --> 01:39.940
And then we are printing the student in here.

01:39.940 --> 01:42.520
What I'm going to do, I'm going to run and then check the result.

01:43.900 --> 01:44.830
As soon as you run it.

01:45.370 --> 01:48.730
You see, earlier we were just printing the result, which is a map.

01:48.820 --> 01:49.960
We take a look at it now.

01:49.960 --> 01:56.920
It is printing all the values as you see it is printing all the students which are being parsed as part

01:56.920 --> 01:57.370
of the student.

01:57.370 --> 01:58.420
How many students are there?

01:58.420 --> 02:01.000
One, two, three, four, five, six.

02:01.000 --> 02:02.230
There are six students.

02:02.500 --> 02:09.280
Our collection, our student database, get all students also has six students, as you see here.

02:09.460 --> 02:10.390
Student one to.

02:10.390 --> 02:12.350
Student six That's good.

02:12.370 --> 02:18.310
Now we want to see how many students are getting filtered and then passed to the next level in this

02:18.310 --> 02:19.210
student predicate.

02:19.240 --> 02:24.910
So in this student predicate, basically we have the filter which is equal to greater than or equal

02:24.910 --> 02:25.570
to three.

02:25.660 --> 02:32.770
Let's write the peak method and then see how many students are getting passed from this filter to this

02:32.770 --> 02:33.460
filter.

02:33.820 --> 02:35.230
So I'm going to have.

02:36.050 --> 02:39.320
This one printed as after first filter.

02:42.500 --> 02:45.410
Then I'm going to run this example.

02:45.410 --> 02:49.730
Now let's see how many occurrences of this is printed in the console.

02:51.090 --> 02:55.530
I am expecting for because we have like two students in each grade.

02:55.530 --> 02:59.820
We have two, three and four four grades as part of the.

03:00.630 --> 03:01.830
It all students with it.

03:01.950 --> 03:02.630
We take a look at it.

03:02.640 --> 03:03.180
Second grade.

03:03.180 --> 03:06.870
We have two students, third grade, we have two students and fourth grade.

03:06.870 --> 03:08.130
We have two students.

03:08.400 --> 03:14.040
Basically, with this filter going to just print four students, go ahead and take a look at it.

03:15.390 --> 03:16.830
So here.

03:19.020 --> 03:20.850
One, two, three, four.

03:20.880 --> 03:23.700
It gave me four values in the result.

03:23.700 --> 03:30.330
Meaning it printed it, applied the filter, and then it filtered out two students from this actual

03:31.410 --> 03:34.560
students method which returned you six students.

03:34.590 --> 03:40.950
Now what I'm going to do, I'm going to add this peek method here to and then see here I'm going to

03:40.950 --> 03:43.800
name this one as after second filter.

03:44.980 --> 03:46.300
After the second filter.

03:46.330 --> 03:50.410
Let's see how many students are going to be passed from this level to the collector.

03:51.570 --> 03:52.440
And thus.

03:57.000 --> 03:58.470
Bring it up a little bit.

03:58.980 --> 03:59.840
Search for it.

03:59.850 --> 04:02.040
We have like three matches here.

04:02.070 --> 04:03.270
This is what is happening.

04:03.270 --> 04:11.220
So it is applying the second filter, which eventually resulted in passing three students to the.

04:12.730 --> 04:14.410
Actual collector.

04:14.410 --> 04:19.510
And if you take a look at it, it's not just like the whole collection.

04:19.510 --> 04:20.740
It is in sequence.

04:20.740 --> 04:23.080
So first filter and then the second filter.

04:23.080 --> 04:24.910
First filter and then the second filter.

04:24.910 --> 04:27.910
So it applies the filters to the elements one by one.

04:27.910 --> 04:30.940
Basically stream is parsing the elements.

04:32.340 --> 04:38.040
Stream is parsing the elements from the top to the bottom one by one, and it is applying the filter

04:38.040 --> 04:39.960
on the elements one by one.

04:41.140 --> 04:49.210
So this is the way we can debug and then see what is being passed from one operation to the other operation.

04:49.340 --> 04:51.550
So the method is called the peek method.

04:52.150 --> 04:54.290
With this we came to the end of this tutorial.

04:54.310 --> 04:55.360
Thank you for watching.
