zoukankan      html  css  js  c++  java
  • Lambda表达式使用整理

    1、List转换

    List<String> departmentIdList = userList.stream().map(e -> e.getDepartmentId()).collect(Collectors.toList());

    2、List转换并且转换为Set

    Set<String> departmentIdSet = userList.stream().map(e -> e.getDepartmentId()).filter(e -> ValidateUtil.isNotNull(e)).collect(Collectors.toSet());

    3、过滤

    Set<String> departmentIdSet = userList.stream().map(e -> e.getDepartmentId()).filter(e -> ValidateUtil.isNotNull(e)).collect(Collectors.toSet());

    4、List转换为Map

    Map<String, String> deptMap = userDeptList.stream().collect(Collectors.toMap(e -> e.getDeptId(), e -> e.getDeptName()));

    5、使用代码块进行转换

    List<String> menuCodeList=menuFunctionList.stream().map(e->{
    String menuCodeTemp=e.getMenuCode();
    String menuCode = menuCodeTemp.substring(menuCodeTemp.lastIndexOf("_")+1);
    return menuCode;
    }).collect(Collectors.toList());


    6、分组转换
    //单一分组条件,根据code
    Map<String, List<Student>> singleMap = studentList.stream().collect(Collectors.groupingBy(Student::getCode));
     //组合分组条件
    Map<String, List<Student>> complexMap = studentList.stream().collect(Collectors.groupingBy(e -> fetchGroupKey(e)));
    List<Student> studentList1 = complexMap.get("yangtao+1");
    List<Student> studentList2 = complexMap.get("yangtao+2");
    private static String fetchGroupKey(Student student){
       return student.getUsername() +"+"+ student.getCode();
    }
  • 相关阅读:
    Echart 动态生成series数据
    转换Excel格式
    .NET接收邮件下载邮件附件——openpop.net
    百度Echart 地图
    mobiscroll 日期问题
    jQuery自动完成插件flexselect
    HTML5 video 连续播放视频
    team foundation server 工具的使用
    实现主成分分析与白化
    白化(预处理步骤)【转】
  • 原文地址:https://www.cnblogs.com/dancser/p/12560927.html
Copyright © 2011-2022 走看看