1.stream根据指定字段去重
List<RiskTemplateIndicatorCategory> afterIndcatorList = indcatorList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(RiskTemplateIndicatorCategory::getId))), ArrayList::new));
2.stream根据指定字段排序(默认正序排列,如果要倒序在后面加reverse即可)
analysisList = analysisList.stream().sorted(Comparator.comparing(RiskVo::getOneLevelId)).collect(Collectors.toList());
3.stream根据指定字段值过滤数据
List<AnalysisVo> sysIndicate = analysisList.stream().filter(item -> StringUtils.equals("195", item.getOneLevelId())).collect(Collectors.toList());
4.stream根据指定字段值求平均
Double avg = mapRecords.stream().collect(Collectors.averagingDouble(riskRankForUnitVo -> Double.parseDouble(riskRankForUnitVo.getSafetyScore())));
5.stream根据指定字段值求最小值
double min = mapRecords.stream().collect(Collectors.summarizingDouble(riskRankForUnitVo -> Double.parseDouble(riskRankForUnitVo.getSafetyScore()))).getMin();
6.stream根据指定字段值排序取topN
List<TRiskAssessRecord> collect = noRepeatList.stream().sorted(Comparator.comparing(TRiskAssessRecord::getTotalScore)).limit(3).collect(Collectors.toList());