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());

  • 相关阅读:
    codeforces 363B
    hdu 1075 字典树
    D
    C A Simple Job
    Washing Plates 贪心
    HDU 4143 A Simple Problem 分解因式
    ACdream 1236 Burning Bridges 割边 + 去重边
    E. Beautiful Subarrays 字典树
    反素数 -- 数学
    Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组
  • 原文地址:https://www.cnblogs.com/michaelShao/p/6690231.html
Copyright © 2011-2022 走看看