int countMax = appleList.stream().mapToInt(Apple::getCount).max().getAsInt(); //最大值
int countMin = appleList.stream().mapToInt(Apple::getCount).min().getAsInt(); //最小值
int sum = appleList.stream().mapToInt(Apple::getCount).sum(); //和
double average = appleList.stream().mapToInt(Apple::getCount).average().getAsDouble();//平均值
//一次性得到某个属性的所有聚合值(两种方式)
IntSummaryStatistics intSummary_1 = appleList.stream().mapToInt(Apple::getCount).summaryStatistics();
IntSummaryStatistics intSummary_2 = appleList.stream().collect(Collectors.summarizingInt(Apple::getCount));
//直接得到聚合的对象
Apple max = appleList.stream().max(Comparator.comparing(Apple::getType)).get();
bigdecimal需要用到reduce求和
BigDecimal示例:
BigDecimal bigDecimal = appleList.stream().map(Apple::getPrice).reduce(BigDecimal::add).get();