WEBVTT

00:00.080 --> 00:00.560
Hi everyone.

00:00.560 --> 00:01.850
Welcome back to this tutorial.

00:01.850 --> 00:08.180
In this tutorial we will code and learn the map two Object map to long and map to double function as

00:08.180 --> 00:10.040
part of the streams API.

00:10.070 --> 00:12.500
The first one is map to object.

00:12.500 --> 00:17.180
This is used to convert each element in the numeric stream to some object.

00:17.540 --> 00:22.580
Don't worry, if this doesn't make sense, we'll be able to understand when we actually code this in

00:22.580 --> 00:23.210
a moment.

00:23.630 --> 00:25.220
The next one is map to long.

00:25.250 --> 00:29.270
This is used to convert a numeric stream to a long stream.

00:29.270 --> 00:30.530
Let's say you have a in stream.

00:30.530 --> 00:35.060
If you want to convert that to a long stream, you just have to call this method that is going to take

00:35.060 --> 00:37.880
care of converting that in stream to a long stream.

00:38.810 --> 00:40.040
The next one is map to double.

00:40.040 --> 00:43.790
This is used to convert a numeric stream to a double stream.

00:43.940 --> 00:48.480
We discussed this example already, but I would like to cover this again as part of this tutorial.

00:48.500 --> 00:49.970
Let's go ahead and code this one.

00:50.900 --> 00:52.790
I have the previous examples still here.

00:52.790 --> 00:58.130
I'm going to close this and create a brand new class for this tutorial.

00:58.580 --> 00:59.750
Let me close this one.

01:01.260 --> 01:01.750
This console.

01:02.170 --> 01:07.060
Now we will create a class called Numeric

01:09.040 --> 01:12.520
Stream Map example.

01:14.170 --> 01:17.410
Let's make this class executable by adding public static void main method.

01:21.120 --> 01:24.630
The first method that we are going to explore is map to object.

01:24.780 --> 01:32.610
I'm going to create public static void map to object is a method that we are going to explore.

01:32.640 --> 01:39.990
The first step is I'm going to create a stream dot range and empty range closed.

01:40.380 --> 01:42.020
I'm going to give the value as five.

01:42.030 --> 01:45.510
So it's going to have it's going to create an stream of five elements.

01:45.810 --> 01:50.760
I want to use the map to object method, as you see here, the map to object method.

01:50.760 --> 01:54.030
It takes in an INT function as an input.

01:54.060 --> 01:59.640
So our goal is going to be we are going to take this value.

02:00.930 --> 02:04.980
And then we are going to return a new integer.

02:06.030 --> 02:06.830
Return.

02:06.840 --> 02:08.160
New integer.

02:09.090 --> 02:11.820
And then I'm going to pass the value here.

02:13.330 --> 02:20.440
So in the place of New Integer, if we have any custom object, we can still use it.

02:20.440 --> 02:25.300
But the input for that custom object is going to be this integer.

02:25.300 --> 02:29.620
And after that, what I'm going to do, I'm going to do a collect of.

02:30.350 --> 02:30.740
List.

02:34.350 --> 02:39.690
And I'm going to do a static import of collector, as you see here, the static import of collector.

02:39.690 --> 02:42.180
I'm going to return this return.

02:42.180 --> 02:42.660
What is that?

02:42.660 --> 02:43.260
It is returning.

02:43.260 --> 02:46.110
It is returning a list of integer.

02:46.410 --> 02:47.790
That's what it is going to return.

02:48.450 --> 02:49.230
There you go.

02:49.890 --> 02:50.410
Sounds good.

02:50.430 --> 02:52.770
Let's call this method and print the result.

02:54.180 --> 02:57.300
So I'm going to name this one as map to object.

02:58.680 --> 03:03.090
And then let's call this let's run this example.

03:03.090 --> 03:04.530
I'm going to run this example.

03:05.910 --> 03:07.140
Then as I run the example.

03:07.140 --> 03:07.770
There you go.

03:07.770 --> 03:14.940
So we have successfully used the map to object to convert a int stream to a list of integers.

03:14.940 --> 03:19.800
So in the place of integer, if you have any custom class that just takes in an int as an input and

03:19.800 --> 03:22.620
then creates a object, you can go ahead and use this one.

03:23.400 --> 03:26.940
And the next one is we are going to explore the map too long.

03:27.870 --> 03:33.330
Public static want to create the method with void will change the return type.

03:33.330 --> 03:38.280
After we code our use case completely, it's going to be map to long.

03:39.930 --> 03:42.210
So again, I'm going to use a in stream.

03:42.300 --> 03:43.430
There we go.

03:43.440 --> 03:48.990
And here we're going to use the map to long method in the map to long method.

03:49.020 --> 03:53.310
Basically, you're going to accept an input and return the same input.

03:54.600 --> 03:57.620
And it is going to perform.

03:57.630 --> 04:02.150
I'm going to do a sum sum of all the numbers.

04:02.160 --> 04:04.320
So this one will convert.

04:08.470 --> 04:11.050
In stream to long stream.

04:12.760 --> 04:17.710
If you go to this map to long method, you can see the return type of that method is long stream.

04:17.830 --> 04:21.790
The input that it accepts is the I value that is being passed from here.

04:22.180 --> 04:30.490
This is a in stream and I value is passed from the end string.

04:31.570 --> 04:32.140
There we go.

04:32.320 --> 04:35.650
And what we are going to do, we are going to return this.

04:37.800 --> 04:39.900
Going to be long.

04:41.380 --> 04:44.740
Then run this and check.

04:45.580 --> 04:47.320
Going to be mapped along.

04:48.040 --> 04:48.940
Mapped along.

04:49.770 --> 04:50.970
Go ahead and run this one.

04:54.050 --> 04:55.190
So there you go.

04:55.280 --> 04:56.930
The result is map to long.

04:57.080 --> 05:01.070
The next method, which we are going to explore, it's going to be map to double.

05:01.100 --> 05:02.240
That's the next method.

05:03.050 --> 05:07.340
It's going to be map to double.

05:07.670 --> 05:10.910
So in the place of this, we are going to use map to double.

05:13.260 --> 05:13.530
Okay.

05:14.340 --> 05:16.290
And then the return type is going to be double.

05:16.290 --> 05:19.200
This is going to convert a in stream to.

05:20.590 --> 05:27.430
Double stream and then we are performing summation on that double value.

05:28.310 --> 05:30.220
Okay, I'm going to call this one.

05:30.370 --> 05:32.170
It's going to be map to double.

05:32.260 --> 05:36.520
And this is going to be map to double to this example.

05:38.830 --> 05:40.900
The silt is 15.0.

05:41.530 --> 05:42.670
This of type double.

05:42.870 --> 05:48.670
So this is all about map to object map to long and map to double.

05:49.150 --> 05:51.010
With this we came to the end of this tutorial.

05:51.040 --> 05:51.730
Thank you for watching.
