zoukankan      html  css  js  c++  java
  • Java 8 sort分类

    首先根据降序的sort方法,对list集合中的对象的某个属性进行排序.float getFollowDegree()的返回值时,所以查询出来后进行排序的顺序是降序(DESC,从大到小)的,如果没有reversed()方法的话,就是升序排列(ASC,从小到大).

    reversed()作用:有它就是从大到小排列,没有就是从小到大排列

    //对listResult进行排序,根据伴随度进行降序F
    List<FollowIMSI> collect = listResult.stream()
    .sorted(Comparator.comparing(FollowIMSI::getFollowDegree).reversed())
    .collect(Collectors.toList());

    我们需要的是对followDegree的值降序,如果值相等,再对codeDaysThirty进行降序.所以说,上述代码的理解应该为:
    以codeDaysThirty进行降序排列,如果codeDaysThirty相等,再以followDegree进行排序.

    所以正确的代码应该是:
    //根据伴随度和30天出现比率进行排序
    List<FollowIMSI> collect1 = list1.stream()
    .sorted(Comparator.comparing(FollowIMSI::getFollowDegree)
    .thenComparing(FollowIMSI::getCodeDaysThirsty).reversed())
    .collect(Collectors.toList());
    注意在getFollowDegree()后是没有reversed()的....

  • 相关阅读:
    关于ThreadLocal的理解
    常用Linux软件安装
    Spring事务注解@Transactional失效的问题
    使用jackson转换xml格式数据进行响应
    创建简单web程序了解servlet
    JDBC
    StringBuild类
    Canlendar 日期类
    Java Date 时间类的使用
    QWeb
  • 原文地址:https://www.cnblogs.com/thcy1314/p/10342205.html
Copyright © 2011-2022 走看看