The Collectors.reducing Method
//The following example retrieves the total age of members of each gender:
Map<Person.Sex, Integer> totalAgeByGender =
roster
.stream()
.collect(
Collectors.groupingBy(
Person::getGender,
Collectors.reducing(
0,
Person::getAge,
Integer::sum)));
The reducing operation takes three parameters: identity, mapper and operation.