zoukankan      html  css  js  c++  java
  • java8 按两个属性分组,并返回扁平List; stream排序

    ---------------

    java8 按两个属性分组,并返回扁平List

        /**
         * 设置大区小区分组排序
         * @param dtoList
         */
        private List<PerformanceDto> getRegionGroupOrderList(List<PerformanceDto> dtoList) {
           return dtoList.stream()
                    .collect(Collectors.groupingBy(PerformanceDto::getLargeRegion, Collectors.groupingBy(PerformanceDto::getSmallRegion)))
                    .entrySet().stream()
                    .flatMap(p -> p.getValue().entrySet().stream().flatMap(a -> a.getValue().stream()))
                    .collect(Collectors.toList());
        }

    排序:

    List<Student> studentList1=studentList.stream().sorted().collect(Collectors.toList());//自然序列
    
    List<Student> studentList2=studentList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());//逆序
    
    List<Student> studentList3=studentList.stream().sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());//根据年龄自然顺序
    
    List<Student> studentList4=studentList.stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());//根据年龄逆序
  • 相关阅读:
    BeanUtils.copyProperties的用法
    WinRAR下载
    安装Perl
    @Value设置默认值
    AutoHotkey
    解决springboot启动日志异常问题
    除以2换成位移操作(骚)
    IDEA生成doc文档生成chm文档
    VMWare虚拟机网络配置
    EOF小结
  • 原文地址:https://www.cnblogs.com/longling2344/p/7505998.html
Copyright © 2011-2022 走看看