Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

What Does GroupBy mean in Stream?

4 min readSep 7, 2026

--

Press enter or click to view image in full size

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:

Press enter or click to view image in full size

So, the first letter of a name must be the same in order for it to be accepted into the group.

Press enter or click to view image in full size

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.

--

--

Sivaram Rasathurai
Sivaram Rasathurai

Written by Sivaram Rasathurai

Software Engineer | Java, Spring Boot & Distributed Systems | 6.4K+ Stack Overflow reputation & 3.7M+ content reach | Writing about software engineering

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.