zoukankan      html  css  js  c++  java
  • Java8-排序

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Apple {
        private int wight;
    }

    排序

    List<Integer> numList = new ArrayList<>(Arrays.asList(10, 50, 5, 200, 9, 25));
    List<Apple> applelist = new ArrayList<Apple>() {
        {
            add(new Apple(10));
            add(new Apple(50));
            add(new Apple(5));
            add(new Apple(400));
            add(new Apple(9));
        }
    };
    // 常规升序
    numList = numList.stream().sorted().collect(Collectors.toList());
    // 常规逆序
    numList = numList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    // 根据重量升序
    List<Apple> applelist1 = applelist.stream().sorted(Comparator.comparing(Apple::getWight))
            .collect(Collectors.toList());
    // 根据重量逆序
    List<Apple> applelist2 = applelist.stream().sorted(Comparator.comparing(Apple::getWight).reversed())
            .collect(Collectors.toList());
    // lumbda排序
    Collections.sort(applelist, (e1, e2) -> {
        return e1.getWight() - e2.getWight();
    });
  • 相关阅读:
    视图和触发器
    45题的难点
    表连接、Tsql基本编程和存储过程
    五种函数、子查询和分页查询
    语句创建数据库表及增删改查
    约束
    pyhton的参数类型
    python的数组与集合
    python基础--编码
    NSIS的Push与Pop
  • 原文地址:https://www.cnblogs.com/zincredible/p/10577255.html
Copyright © 2011-2022 走看看