Collectors.sumBy

Paul Sandoz paul.sandoz at oracle.com
Wed Jun 5 09:50:45 PDT 2013


On Jun 5, 2013, at 6:31 PM, Michael Nascimento <misterm at gmail.com> wrote:

> Hi folks,
> 
> Is there any good reason I cannot see for Collectors.sumBy, giving one
> could use mapToLong().sum() and avoid the costs of boxing?
> 

Such Collector can be used with mapping, groupingBy and partitioningBy, e.g.

 Stream<Foo> s = ...
 Map<Foo, Long> m = s.collect(groupingBy(Function::identity, sumBy(this::mapFooToLong)));

Paul.


More information about the lambda-dev mailing list