How about computing the average weight of a melon?
For this, we have Collectors.averagingInt(), averagingLong(), and averagingDouble():
double avgWeights = melons.stream()
.collect(Collectors.averagingInt(Melon::getWeight));
How about computing the average weight of a melon?
For this, we have Collectors.averagingInt(), averagingLong(), and averagingDouble():
double avgWeights = melons.stream()
.collect(Collectors.averagingInt(Melon::getWeight));