WEBVTT

00:00.290 --> 00:00.860
Hi everyone.

00:00.860 --> 00:02.150
Welcome back to this tutorial.

00:02.150 --> 00:07.130
In this tutorial we will code and explore the numeric stream ranges.

00:07.280 --> 00:10.640
The first one is in stream, which supports two methods.

00:10.640 --> 00:13.850
One is a range and another one is a range closed.

00:13.880 --> 00:15.410
Both takes into input.

00:15.410 --> 00:19.250
One is the starting value of the stream and another one is the ending value of the stream.

00:19.250 --> 00:26.000
The difference is that the range method excludes the last element that is being passed as a second argument

00:26.000 --> 00:34.090
for this method, for this input value one comma 50 it returns an int stream of 49 elements from 1 to

00:34.090 --> 00:34.550
49.

00:34.550 --> 00:39.620
Basically, this will exclude the last element, which is the second argument of this method.

00:39.650 --> 00:46.190
The next one is a range closed method range closed method returns an inter stream of 50 elements.

00:46.190 --> 00:53.240
Basically this is there is no exclusion concept here is going to include the values from 1 to 50.

00:53.840 --> 00:55.280
So similar to the end stream.

00:55.280 --> 01:00.230
The long stream also supports the range and range closed method.

01:00.230 --> 01:05.390
The behavior is the same instead of the stream, it is going to return you the long stream.

01:05.480 --> 01:10.310
So for the double stream it doesn't have both range and range closed.

01:10.310 --> 01:12.290
But there is an alternative approach.

01:12.290 --> 01:14.330
In order to create a double stream.

01:14.330 --> 01:16.760
I'll be showing you that in a moment.

01:16.790 --> 01:19.190
Let's go ahead and code this and explore this.

01:21.620 --> 01:23.000
The numeric stream package.

01:23.000 --> 01:25.700
I'm going to create a class called.

01:26.710 --> 01:27.640
Numeric.

01:28.800 --> 01:29.430
Dream.

01:30.500 --> 01:30.900
Ranges.

01:31.070 --> 01:31.850
Example.

01:33.120 --> 01:33.990
And then.

01:35.010 --> 01:38.130
And add the public static void main method.

01:40.310 --> 01:41.780
This in presentation mode.

01:42.640 --> 01:44.050
So that the code will be clear.

01:44.170 --> 01:52.060
The first step is I'm going to create an inter stream dot range and one comma 50.

01:54.320 --> 01:59.360
So basically, if you take a look at it, this is going to return you an input stream.

01:59.870 --> 02:04.160
So let's give it a name int stream equal to.

02:05.640 --> 02:06.060
Here we go.

02:06.060 --> 02:07.650
We have the stream ready.

02:08.070 --> 02:12.810
Let's check what is the total number of elements it has in stream dot?

02:13.940 --> 02:14.170
Oh.

02:15.420 --> 02:15.870
Ramdas.

02:15.870 --> 02:18.150
It is going to print 49.

02:19.350 --> 02:23.160
Now let's try to do a iteration of it.

02:24.300 --> 02:26.160
Right iteration of.

02:27.500 --> 02:33.740
Each value basically for each takes in a consumer and each value is going to have.

02:36.160 --> 02:36.870
Value.

02:36.880 --> 02:40.180
Plus, I'm going to add a comma here as it will be tough to read.

02:40.660 --> 02:42.040
I'll run this example.

02:42.490 --> 02:43.450
There we go.

02:43.480 --> 02:47.770
We got an exception here because a stream has already been closed.

02:47.800 --> 02:51.580
We all know streams can be iterated only once.

02:51.820 --> 02:53.800
That's the reason why we get this problem.

02:54.070 --> 02:57.340
In that case, I'm going to do it like this.

02:57.730 --> 02:59.770
I'm going to print all the values here.

03:00.250 --> 03:02.350
I'm using this print ln.

03:02.380 --> 03:05.740
I'm going to change this one to print and run this example.

03:06.630 --> 03:07.170
There you go.

03:07.170 --> 03:10.560
It printed the values from 1 to 49.

03:11.530 --> 03:12.030
Right.

03:12.040 --> 03:14.920
Let's go ahead and explore the range closed.

03:14.950 --> 03:16.930
I'm going to copy this and paste it here.

03:17.530 --> 03:20.560
I'm going to be range closed dot for each.

03:20.890 --> 03:22.240
If I do this.

03:23.380 --> 03:26.200
Going to print the values until 40.

03:26.230 --> 03:28.360
I would like to perform the count also here.

03:31.680 --> 03:33.090
This one is going to be.

03:34.040 --> 03:34.490
Found.

03:35.670 --> 03:37.320
Put this inside a suit.

03:39.820 --> 03:43.180
So here we are printing the range closed count.

03:43.210 --> 03:44.530
This is range count.

03:46.590 --> 03:47.730
Range count.

03:49.490 --> 03:51.410
And this one is range.

03:52.770 --> 03:53.280
Closed.

03:55.720 --> 03:56.830
Take a look at the difference.

03:58.670 --> 04:06.650
So the range count printed the value as 49, but the range closed count printed the value as 50 here.

04:08.120 --> 04:12.580
Since we have print it is not printing it in the line.

04:13.340 --> 04:14.450
Add this out.

04:15.360 --> 04:15.780
There you go.

04:16.080 --> 04:20.550
They printed the range closed value as 50 range as 49.

04:20.580 --> 04:22.980
Let's explore this.

04:24.270 --> 04:25.320
But the long stream.

04:26.250 --> 04:27.930
If you are doing a long stream.

04:28.050 --> 04:29.100
Same concept.

04:31.800 --> 04:32.880
Long stream.

04:35.140 --> 04:37.540
And then I'm going to do the same thing here.

04:39.890 --> 04:43.210
So instead of the stream, I'm going to change this one to long string.

04:44.670 --> 04:45.120
Okay.

04:46.060 --> 04:47.100
Then let's print this.

04:51.000 --> 04:51.600
You run it.

04:52.230 --> 04:57.210
So here you have the long stream range count as this that.

04:58.550 --> 04:59.390
Episode here.

04:59.390 --> 05:03.770
So that can be printed in a new line so that it will be easy to read in the console.

05:03.800 --> 05:10.190
So in the console, if you take a look at it, the range closed count is 50 and it printed all the 50

05:10.190 --> 05:10.790
values.

05:10.910 --> 05:16.730
So in the presentation I mentioned, that double stream doesn't have doesn't support the range and range

05:16.730 --> 05:17.030
closed.

05:17.030 --> 05:17.300
Right.

05:17.300 --> 05:18.590
Let's go ahead and explore that.

05:18.830 --> 05:25.340
If you do double stream dot, take a look at it doesn't support the range and range closure, but in

05:25.340 --> 05:28.550
case if you need a double stream, how can we get that?

05:28.670 --> 05:30.470
So the way to get it is.

05:33.470 --> 05:33.980
God.

05:35.490 --> 05:41.910
As there is a method called as long stream and as double stream as double stream is going to give you

05:42.030 --> 05:47.400
all the values converted to double then the for each.

05:47.580 --> 05:48.900
I'm printing this.

05:49.750 --> 05:51.070
There was a sword here.

05:52.800 --> 05:55.770
This, then check the route here.

05:55.770 --> 05:57.840
We take a look at it in the console.

05:57.840 --> 06:01.050
We have 1.02.03.0.

06:01.140 --> 06:07.170
So there is a handy method as double stream, which is part of both in stream and long stream.

06:07.170 --> 06:10.650
Using that, you can create the double stream.

06:11.220 --> 06:16.290
So this is all about range and ranges that you need to know about numeric stream.

06:16.290 --> 06:18.390
With this we came to the end of this tutorial.

06:18.390 --> 06:19.440
Thank you for watching.
