zoukankan      html  css  js  c++  java
  • JDK8 Stream操作整理

    1,forEach

    this.quoteItemList.forEach(p -> p.setMode(mode));

    2,获取对话属性,去重后生成集合

    List<String> projects = this.quoteItemList.stream().map(p -> p.getVersion()).distinct().collect(Collectors.toList());

    3,过滤后汇总

     double totalRealManDay = this.quoteItemList.stream().filter(p -> p.getAssignee().equals(person.getName())).mapToDouble(p -> p.getSpend()).sum() ;

    sum可以改成count等其它函数

    4,排序号取第一个

    ProfitResult monthResult = calcResult.stream().sorted(Comparable::compareTo).filter(p -> p.getPeriod().equals(period)).findAny().get();
    if (monthResult != null) {
    }

    5,分组统计转成Map

    Map<String, Double> monthMap = this.data.stream().filter(p -> p.getVersion().equals(project)).collect(
        Collectors.groupingBy(QuoteItem::getFinishMonth, Collectors.summingDouble(QuoteItem::getEstimate))
    );

    6,分页获取

    //取出一页数据的id列表
    List<String> ids = list.stream().skip((findDoctorVo.getPage() -1) * findDoctorVo.getPagesize())
        .limit(findDoctorVo.getPagesize())
        .map(TeamVo::getTeamId)
        .collect(Collectors.toList());

     7,转换成其它对象

    方式一:
    List<SessionListVo> newList = list.stream().map(SessionListVo::new).collect(Collectors.toList());
    方式二:
    List<SellInfo> saleList = list.stream().filter(p->p.saleValid()).map(info->{
       SellInfo item = new SellInfo();
    item.setProductName(info.getGoodsname());
    return item;
    }).collect(Collectors.toList());

    8,查询并拼接

    String newTags = tags.stream().filter((p) -> !p.equals(this.defaultTag)).collect(Collectors.joining(this.SPLITER)); 
  • 相关阅读:
    sharepoint获取通用路径
    Sharepoint 在网站中创建用户组并添加权限
    ERP失败案例启示录:人是最关键的
    人生主要过渡期
    Windows Server 2012虚拟化性能及十大重要功能
    抢先看:iPhone5整机完整亮相
    未来五年10大关键IT趋势
    [转]完善的资产管理:实现以可靠性为中心的维护管理
    如何摆脱ERP困局
    项目经理的“七宗罪”
  • 原文地址:https://www.cnblogs.com/season2009/p/10245651.html
Copyright © 2011-2022 走看看