I would choose:
IntSummaryStatistics stats = orderEntries
.stream()
.collect(Collectors.summarizingInt(OrderEntry::getAmount));
This option:
IntSummaryStatistics istats = IntStream.of(51,22,50,27,35).
collect(IntSummaryStatistics::new, IntSummaryStatistics::accept,
IntSummaryStatistics::combine);
is the worst, this is exactly what it does IntStream.summaryStatistics, just written explicitly. Thus, there is no advantage to the first option.
I would go with a slightly modified second option, because the collector better reflects the business operation “summing order entry amounts” from my point of view.
source
share