I am working with the IntSummaryStatistics class to calculate out the statistics for my class. I searched for three particular ways to calculate statistics. Here is my code:
IntSummaryStatistics stats1 = orderEntries.stream()
.mapToInt((x) -> x.getAmount()).summaryStatistics();
IntSummaryStatistics stats2 = orderEntries.stream().collect(
Collectors.summarizingInt(o -> o.getAmount()));
IntSummaryStatistics istats2 = orderEntries.stream().
collect(
() -> new IntSummaryStatistics(),
(i,o) -> i.accept(o.getAmount()),
(i1, i2) -> i1.combine(i2));
IntSummaryStatistics istats = IntStream.of(51,22,50,27,35).
collect(IntSummaryStatistics::new, IntSummaryStatistics::accept,
IntSummaryStatistics::combine);
Which one is the better approach? Which one we should prefer over other?