Hi everyone.
Welcome back to this tutorial.
In this tutorial we will code and explore the three argument version of grouping by So in the previous
two tutorials we explored the one argument version and the two argument version.
Right.
Let's go ahead and explore the three argument version.
Before I do that, I would like to explore what is happening with the two argument version.
If we go and take a look at the two argument version, here we are passing the classifier and downstream.
But internally what this does is it passes the third argument here.
So the classifier is passed as a first argument and the HashMap knew this is a supplier which they are
passing.
So the output is always going to be HashMap because here they are performing this internally.
So what we are going to do is we are going to override this and then pass the supplier from our end.
That's what we are going to do as part of the three argument version of grouping by.
That's going to be public static.
Wide.
Three argument.
Group by.
And in here it accepts.
It accepts student database dot get all students dot stream.
And then we're going to call the collect method.
In the collect method, we're going to perform the group by of name.
I'm going to copy this from here.
That is the first argument, which is a classifier and followed by that what are we going to do?
We are going to use the linked hash map, colon, colon, new, that is a supplier.
And the third one is going to be we are going to use the another collector, which is going to be to
set because we have seen.
We have seen lists throughout all these examples, but here we are going to override that and then use
to set as a collector.
So what is the output?
It is going to be linked hash map and the key, what is a key?
The key is going to be the name.
It is of type string.
And then this is going to be set of student.
So let's give it a name.
Let's import the set here.
The name is going to be student.
Linked hash map.
Good.
There you go.
Then I'm going to print this.
And let's revisit this again.
The first one determines the key here.
The second parameter determines the output.
What kind of output it is, what kind of connection it is going to return.
And this two set determines what is a value for the output that it is going to generate.
Let's run this example and then validate the result.
Let's run this.
Going to have a name and their student as a.
Value.
So Adam and the whole student object mapped out.
Jenny And the whole student.
Object mapped to it.
So this is all about the three argument version of grouping by.
But this we came to the end of this tutorial.
Thank you for watching.