Below is learnt from my colleague. Next time i wish i can solve it independently.
?
class="java" name="code">import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.reducing; import static java.util.stream.Collectors.toList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; ... list.stream().collect(groupingBy(item -> item.getType() + item.getLevel(), reducing(Item::summarize))) // summarize: static function to aggregate items .values().stream().map(Optional::get) .collect(toList());
?
?
?
?
?