1.过滤后,对某个字段求和 maptoDouble double sumRackIncome = bizRevenueFlowList.stream() .filter(e->e.getProdCode().equals(Constants.RACK_RENT_OUT_CODE)) .mapToDouble(e -> (Double.parseDouble(e.getTaxesAmount()))).sum();
List<String> businessCollect = businessList.stream().filter( s -> !StringUtils.equals(s.getMonthDate(), monthId)).map(RatioDTO::getMonthDate).collect(Collectors.toList());
mapToLong long ip6Sum = bizCustResourceHistoryDataList.stream() .mapToLong(BizCustResourceHistoryData::getIpv6NumLong).sum();
重写get方法
public String getIpv6Num() { return ipv6Num; } public Long getIpv6NumLong() { return NumberUtil.parseLong(ipv6Num); }
maptoInt int sum = provinceBoutiqueLineNumList.stream() .mapToInt(e -> (Integer.parseInt(e.getNum()))).sum();
map(某个字段) List<String> rackCollect = rackRatioList.stream().map(RatioDTO::getMonthDate).collect(Collectors.toList());
2.排序
comparingLong List<BizCustResourceHistoryData> rackSumList = bizCustResourceHistoryDataList.stream() .sorted(Comparator.comparingLong(BizCustResourceHistoryData::getCabinetN umLong).reversed()) .collect(Collectors.toList());
comparingDouble comparingDoublefirstBizIdcElecFees.stream().sorted(Comparator.comparingDouble(BizIdcElecFee::getElecChargeDouble).reversed()).collect(Collectors.toList());
comparing comparinghistoryList.stream().sorted(Comparator.comparing(RatioDTO::getElecCharge).reversed()).collect(Collectors.toList());
lastBizIdcElecFees.sort(Comparator.comparingDouble(BizIdcElecFee::getElecChargeDouble).reversed());
revenueFlowDtos.sort((x, y) -> Double.compare(Double.parseDouble(y.getTaxesAmount()), Double.parseDouble(x.getTaxesAmount())));
3.分组
直接分组 Map<String, List<BizRevenueFlow>> firstTotaCollect = bizRevenueFlowList.stream().collect(Collectors.groupingBy(BizRevenueFlow::getProvinceId)); 过滤完分组 Map<String, List<BizRevenueFlow>> firstRackCollect = bizRevenueFlowList.stream().filter(e -> e.getProdCode().equals(Constants.RACK_RENT_OUT_CODE)).collect(Collectors.groupingBy(BizRevenueFlow::getProvinceId));ffenzu
分组后求和 private List<RevenueFlowDTO> setSum(Map<String, List<BizRevenueFlow>> collect) { List<RevenueFlowDTO> revenueFlowDtos = new ArrayList(); for (Map.Entry<String, List<BizRevenueFlow>> entry : collect.entrySet()) { String key = entry.getKey(); List<BizRevenueFlow> value = entry.getValue(); Double sum = value.stream().mapToDouble(e -> (Double.parseDouble(e.getTaxesAmount()))).sum(); RevenueFlowDTO revenueFlowDto = new RevenueFlowDTO(); revenueFlowDto.setProvinceId(value.get(0).getProvinceId()); revenueFlowDto.setTaxesAmount(sum.toString()); revenueFlowDtos.add(revenueFlowDto); } revenueFlowDtos.sort((x, y) -> Double.compare(Double.parseDouble(y.getTaxesAmount()), Double.parseDouble(x.getTaxesAmount()))); return revenueFlowDtos; }