void () { Collector<Intermediate, ?, Map<String, Integer>> reducer = Collectors.groupingBy(Intermediate::name, Collectors.summingInt(Intermediate::value)); Map<String, Map<String,Integer>> green = dtos.values() .stream() .flatMap(dto -> dto.getNestedThings() .values() .stream() .map(ppd -> new Intermediate(dto.getName(), ppd.getKey(), ppd.getValue()))) .collect( Collectors.groupingBy( Intermediate::key, reducer )); Map<String, Map<String,Integer>> red = dtos.values() .stream() .flatMap(dto -> dto.getNestedThings() .values() .stream() .map(ppd -> new Intermediate(dto.getName(), ppd.getKey(), ppd.getValue()))) .collect( Collectors.groupingBy( Intermediate::key, Collectors.groupingBy(Intermediate::name, Collectors.summingInt(Intermediate::value)) )); }