Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and explore the summing end and averaging end collector.
The summing in collector is going to return the sum as a result.
The averaging ENT collector is going to return the average as a result.
Like summing.
And this collector has the support for summing long summing double averaging long and averaging double.
But in this tutorial we are going to focus only on the summing ent and averaging ent.
Let's go ahead and code this one.
To have the example here.
I close all these previous examples?
In here what I'm going to do, I'm going to create a class called Dreams.
Some average example.
Let's make this class executable by adding public static void main method.
Kostas console.
Let me put this in presentation mode.
The first example is we are going to explore the sum.
Public static int.
Okay, now we are going to use a student database class and get all the students.
The use case that we are going to code is that if you take a look at this student object, it has a
property called notebooks.
So our use case is to perform summation of all the notebooks this whole student collection has.
That's a use case use case.
We are going to code.
So after the student, after we got all the students, we are going to call the stream method.
In the stream method we are going to perform the collect operation in here.
We are going to call summing int.
That's a character we are going to make use of.
Use of it in this scenario and what we are going to pass, we are going to pass within Colon.
Colon.
Let's import the student first.
Some reason it is not giving me the recommendation.
Let's put both the colons here.
I believe it is going to give you the recommendation now.
There you go.
We have successfully imported the student and in here we are going to use the get notebooks, which
is going to return the notebooks of each and every student.
And the collect is going to accumulate all the values by performing the summation of each value that
is being passed from the stream and return the result.
So I'm going to add the return statement here.
This return statement is going to return the whole summation of all the notebooks from all the students
I'm going to print.
The value here is going to be total number of notebooks.
And then the method that it is going to call is sum.
Let's run this example and check the result.
There you go.
It printed the result as 71.
So this is all about the summing int let's explore the averaging int.
So I'm going to name this one as average.
And then instead of summing it, we are going to use averaging and there you go, averaging it.
Like I mentioned in the presentation, it has the long version and double version too, but we are going
to focus only on the averaging end.
And if we take a look at the averaging end, it returns a type as double.
So we are going to return the type as double.
But s going to be.
Average number of notebooks.
Is a text, which I'm going to add, and then we are going to call the average method.
So the average method performs a averaging and let's go ahead and run this one.
So the average number of notebooks that each and every student has is 11.83.
So this is all about summing and and averaging it collector.
But this.
We came to the end of this tutorial.
Thank you for watching.