ListIn the above code, we use the Person::getAge method reference to specify the property by which to group the objects. The resulting map has two keys - 25 and 30 - and the corresponding lists of Person objects. The java.util.stream.Collectors.groupingBy method is part of the Java standard library, specifically the java.util.stream package.people = Arrays.asList( new Person("John", 25), new Person("Mary", 30), new Person("Peter", 25), new Person("Lucy", 30) ); Map > groupsByAge = people.stream() .collect(Collectors.groupingBy(Person::getAge)); System.out.println(groupsByAge); // output: {25=[Person{name='John', age=25}, Person{name='Peter', age=25}], 30=[Person{name='Mary', age=30}, Person{name='Lucy', age=30}]}