Skip to content
Veltoryx Technologies
ProLesson 8.5Intermediate2 min readUpdated 30 October 2026

Collectors: grouping, partitioning, joining

Turn streams into lists, sets, maps and reports with Collectors, including groupingBy, partitioningBy, counting, summing and joining.

collect is the most powerful terminal operation. Together with the Collectors helper class, it turns a stream into almost any result: a list, a map, a grouped report or a single string.

01The data for this lesson

java
record Employee(String name, String dept, double salary, int years) { }

List<Employee> staff = List.of(
        new Employee("Asha", "Engineering", 120000, 5),
        new Employee("Ravi", "Engineering", 95000, 2),
        new Employee("Bala", "Sales", 70000, 7),
        new Employee("Jo", "Sales", 65000, 1),
        new Employee("Meera", "HR", 60000, 3));

Loading the rest of the lesson…