WEBVTT

00:00.470 --> 00:00.980
Hi everyone.

00:00.980 --> 00:02.270
Welcome back to this tutorial.

00:02.270 --> 00:06.080
In this tutorial we will code and explore the mapping Collector.

00:06.880 --> 00:14.120
Mapping collector applies a transformation function first and then collects the data in a collection.

00:14.140 --> 00:15.850
The collection could be of any type.

00:15.850 --> 00:17.440
It could be a list set.

00:17.470 --> 00:20.110
Let's go ahead and explore this using an example.

00:20.770 --> 00:23.230
I've then open here what I'm going to do.

00:23.260 --> 00:24.820
I'm going to create a.

00:25.750 --> 00:29.470
A class called frames Mapping.

00:29.800 --> 00:30.700
Example.

00:32.430 --> 00:37.530
And then I'm going to make this class executable by adding public static void main.

00:39.580 --> 00:41.110
We put this in presentation mode.

00:44.120 --> 00:44.930
What I'm going to do.

00:44.930 --> 00:51.440
I'm going to call the student database class dot, get all students, and then call the stream method.

00:52.250 --> 00:55.130
Followed by that we are going to call the collect method.

00:55.160 --> 00:58.100
In here we are going to call the mapping method.

00:59.550 --> 01:00.000
Right.

01:00.540 --> 01:01.650
Import this.

01:02.860 --> 01:04.630
Have the static import option available.

01:04.630 --> 01:05.950
I'm going to select that option.

01:06.310 --> 01:09.010
If you take a look at it, mapping takes two input.

01:09.040 --> 01:14.830
One is the function, which is a mapper, and another one is a downstream, which represents what is

01:14.830 --> 01:18.100
a type of collection which you want the result to be collected.

01:19.360 --> 01:22.180
So I just want the student names.

01:22.720 --> 01:23.560
Student.

01:24.730 --> 01:25.510
This is a function.

01:25.510 --> 01:25.870
Colon.

01:25.870 --> 01:26.470
Colon.

01:29.010 --> 01:30.090
Import the student.

01:31.510 --> 01:33.160
Put class Colon.

01:33.160 --> 01:33.660
Colon.

01:33.670 --> 01:34.690
Get name.

01:35.470 --> 01:38.200
Followed by that you're going to do to.

01:41.760 --> 01:43.660
Wait for this.

01:43.740 --> 01:44.160
There you go.

01:44.310 --> 01:48.570
And then this is going to collect the list of students.

01:50.220 --> 01:52.530
Names which are of type string.

01:54.170 --> 01:54.860
Names list.

01:56.370 --> 01:58.860
We go import this?

01:59.430 --> 02:01.200
What are the java.util package?

02:01.620 --> 02:02.850
Let's print this one.

02:04.260 --> 02:05.640
Names list.

02:10.090 --> 02:10.820
Does this one.

02:10.840 --> 02:13.300
Let's go ahead and run this and check the result.

02:16.750 --> 02:19.180
We printed all the names in the list.

02:19.210 --> 02:20.110
Now.

02:21.570 --> 02:24.600
I'm going to do the same kind of operation I'm going to collect.

02:24.600 --> 02:30.270
I'm going to use the name to be mapped, but I want to collect the result in a set.

02:34.710 --> 02:38.920
Pass to set is going to be set of strings.

02:38.940 --> 02:40.470
Let's import this.

02:40.500 --> 02:44.220
This is going to be I'm going to give it a new name called Names Set.

02:44.920 --> 02:46.170
I'll copy this out.

02:46.560 --> 02:47.560
Put it here.

02:47.580 --> 02:48.990
Let's import this to set to.

02:49.020 --> 02:53.280
This is going to be a static import here like the way we did for to list.

02:54.630 --> 02:56.370
And here I'm going to print the names.

02:58.940 --> 03:00.800
Run this and check the result.

03:02.410 --> 03:02.890
Result.

03:03.520 --> 03:07.090
We printed the it collected the names in a set.

03:07.120 --> 03:10.120
If you remember this, in the past we used to do.

03:11.380 --> 03:14.980
Me for this one without.

03:16.250 --> 03:17.870
The mapping method in the past.

03:17.870 --> 03:24.380
If we just want the names, what we do is we call the map method and then student Colon, Colon, get

03:24.410 --> 03:27.200
name, and then we use the collect.

03:27.800 --> 03:29.000
We give it as to list.

03:30.640 --> 03:33.640
So with this we can avoid one additional.

03:33.640 --> 03:39.760
With this mapping method, we can avoid that additional intermediate operation and then we can perform

03:39.760 --> 03:42.130
everything using the mapping method.

03:43.330 --> 03:45.380
So this is all about mapping method.

03:45.400 --> 03:47.560
With this, we came to the end of this tutorial.

03:47.590 --> 03:48.640
Thank you for watching.
