stream基本操作

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;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值