java8Stream運算元組進行排序和過濾
阿新 • • 發佈:2018-10-31
//對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排序
根據匹配次數正序排列,從小到大.