java8Stream操作数组进行排序和过滤

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

根据集合中对象FollowIMSI中的伴随度进行倒序排列...reversed(),默认正序,reversed反转后即倒序;

 List<CollisionEntity> firstA = listEntity.stream()
                .filter(collisionEntity -> collisionEntity.getMatchNums() >= 2)
                .collect(Collectors.toList());

过滤,过滤掉collisionEntity中匹配次数多于两次的结果,firstA中存放的都是多于两次的


      List<CollisionEntity> result = firstA.stream()
            .sorted(Comparator.comparing(CollisionEntity::getMatchNums))
            .collect(Collectors.toList());//根据matchnums排序

根据匹配次数正序排列,从小到大.

猜你喜欢

转载自blog.csdn.net/YoungLee16/article/details/82688067