list集合根据某字段获取最大值、最小值等

//最大值
int maxValue = list.stream().mapToInt(User::getScore).max().getAsInt();
long maxValue = list.stream().mapToLong(User::getScore).max().getAsLong();
double maxValue = list.stream().mapToDouble(User::getScore).max().getAsDouble();
BigDecimal maxValue = list.stream().map(User::getScore).reduce(BigDecimal.ZERO, BigDecimal::max);
//最小值
int minValue = list.stream().mapToInt(User::getScore).min().getAsInt();
long minValue = list.stream().mapToLong(User::getScore).min().getAsLong();
double minValue = list.stream().mapToDouble(User::getScore).min().getAsDouble();
BigDecimal minValue = list.stream().map(User::getScore).min(BigDecimal::compareTo).get();
//求和
int sumValue = list.stream().mapToInt(User::getScore).sum();
long sumValue = list.stream().mapToLong(User::getScore).sum();
double sumValue = list.stream().mapToDouble(User::getScore).sum();
BigDecimal sumValue = list.stream().map(User::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
//平均数
double averageValue = list.stream().mapToInt(User::getScore).average().getAsDouble();
double averageValue = list.stream().mapToLong(User::getScore).average().getAsDouble();
double averageValue = list.stream().mapToDouble(User::getScore).average().getAsDouble();

 

posted @ 2022-08-29 18:18  一隅桥畔  阅读(1858)  评论(0)    收藏  举报