Club Signup Summary with groupingBy()
A school activity fair lets students sign up for different clubs throughout the day. By the time registration closes, the office has a long list of slips in the format "Club:Student". The staff wants one grouped summary so they can see which students joined each club without manually sorting every paper slip.
Your task is to read that list and return a map where each key is a club name and each value is the list of students who signed up for that club. The student order inside each list should follow the original arrival order of the slips for that same club.
For example, if the slips are ["Chess:Ayu", "Art:Bima", "Chess:Cici"], the result should be a map where "Chess" points to ["Ayu", "Cici"] and "Art" points to ["Bima"]. If a club appears many times, all of its student names should collect into the same list.
This challenge is a little richer than a basic filter or map problem. You are not just transforming one value into another. You are classifying each slip by club name, extracting the student part, and collecting related values into buckets. That is exactly the kind of task where Collectors.groupingBy() becomes useful.
The input format is intentionally simple so the focus stays on the stream pipeline. Each slip always has one club name, a colon, and one student name. The final answer should be a grouped summary map that is easy for the school office to read and use.
Example Input & Output
A one-slip input still becomes a grouped map with one list value.
Multiple students can collect into the same club bucket.
Slips are grouped by club, and the student names are collected in arrival order.
Algorithm Flow

Solution Approach
This is a strong use case for Collectors.groupingBy() because the core task is classification. Every slip belongs to one club, and all slips for the same club should end up in the same group.
The stream needs to do two related things. First, determine the grouping key: the club name before the colon. Second, store the student name after the colon rather than storing the entire original slip string. That means groupingBy() pairs nicely with Collectors.mapping().
A stream solution often looks like this:
Here, the classifier decides the club bucket, and the downstream mapping() collector extracts only the student part for the stored list values. Using LinkedHashMap also keeps the club groups in encounter order, which can make the result easier to read.
This problem feels medium because there are several moving pieces in one pipeline: parsing, grouping, and transforming what gets stored inside each group. But the overall structure is still very readable once you see the classification pattern.
The runtime is O(n) for n slips, assuming normal map operations. The key learning point is that groupingBy() is not only about counting; it is also an excellent tool for building organized grouped collections from flat input data.
Best Answers
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
class Solution {
public static Map<String, List<String>> buildClubSummary(List<String> slips) {
return slips.stream()
.collect(Collectors.groupingBy(
slip -> slip.split(":")[0],
LinkedHashMap::new,
Collectors.mapping(slip -> slip.split(":")[1], Collectors.toList())
));
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
