Collectors.groupby example : How to do group by in java

Java Collectors.groupby() example
We have already seen some examples on Collectors in previous post.  In this post, we are going to see Java 8 Collectors groupby example. Groupby is another feature added in java 8 and it is very much similar to SQL/Oracle.
Lets understand more with the help of example: Lets create our model class country as below:
Lets create main class in which we will use Collectors.groupBy to do group by.
When you run above class, you will get below output:

[{India,20000}, {India,50000}] {China=2, Nepal=1, India=2}
{China=50000, Nepal=30000, India=70000}

Reference: 
https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *