zoukankan      html  css  js  c++  java
  • java8 stream sorted

    1.对象类型配列
      List<Person> list = Arrays.asList(
        new Person(22, "shaomch", "man"),
        new Person(26, "mike", "wemon"),
        new Person(24, "tom", "wemon"),
        new Person(22, "tom", "wemon")
      );
      //升序排列
      List<Person> list1 = list.stream().sorted(Comparator.comparing(Person::getAge)).collect(Collectors.toList());
      //降序排列
      List<Person> list2 = list.stream().sorted(Comparator.comparing(Person::getAge).reversed()).collect(Collectors.toList());
    2.Integer类型排列
      List<Integer> integerList = Arrays.asList(1,4,56,2,3,5,10);
      //升序
      List<Integer> integerList1 = integerList.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
      //降序
      List<Integer> integerList2 = integerList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    3.String类型排列
      List<String> strList = Arrays.asList("shaomch", "mike", "tom", "tom");
      //升序
      List<String> strList1 = strList.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
      //降序
      List<String> strList2 = strList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());

  • 相关阅读:
    input.file上传图片| FileReader h5新特性
    lua的luasocket程序
    nginx的proxy_set_header
    lua的table.sort
    lua的深拷贝和浅拷贝
    nginx的location匹配
    kong后台接口
    一些程序和工具
    lua的模式匹配
    php的一些语法
  • 原文地址:https://www.cnblogs.com/michaelShao/p/6690231.html
Copyright © 2011-2022 走看看