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)); 
  • 相关阅读:
    【队列】队列的分类和实现
    【JSP】EL表达式语言
    【JSP】JSP的介绍和基本原理
    【JSP】JSP Action动作标签
    【Servlet】关于RequestDispatcher的原理
    【JSP】JSP指令
    【JSP】JSP中的Java脚本
    【算法】表达式求值--逆波兰算法介绍
    C语言指针详解
    移动架构-MVVM框架
  • 原文地址:https://www.cnblogs.com/season2009/p/10245651.html
Copyright © 2011-2022 走看看