Member-only story
What Does GroupBy mean in Stream?
I’m assuming you already have experience with Java 8 and are familiar with stream, filter, and map. This would help you understand Groupby.
Let's think we have a list like this,
List<String> names = List.of("Siva", "Sri", "Ram",
"Kumar", "Raja", "Ranjan",
"Sutha", "Sankar", "Venu");We must identify and categorize the names according to their first letters, such as:
So, the first letter of a name must be the same in order for it to be accepted into the group.
Why is the result is Map?
.groupingBy(name -> name.charAt(0))Imagine that we are going to form a bucket or group. What do we need first?
We should label the group, which is what we do in the groupingBy
We should tell JVM how to label each element in the list.










