Advanced Grouping with Java streams

The problem I have a list of Person objects. I would like to group them per birth month, and only keep a List of lastnames. I came up with this code from memory Map<String, List<Person>> personsByMonth = persons.stream() .collect(Collectors.groupingBy(Person::getBirthMonth)); System.out.println(personsByMonth); And you get the following output (truncated for readability): {JUNE=[Person{lastName='Doe 11', birthDate=2022-06-07}], JANUARY=[Person{lastName='Doe 10', birthDate=2023-01-26}]} But how do I get rid of the redundant information? The solution The Collectors class provides quite a lot of variation of the groupingBy method....

May 22, 2023 ยท 2 min