/**
* 处理数组对象倒序排列
*
* @param openMeetingList list对象数组
*/
private void reversedSort(List<MeetingInfoAndSubscribeInfoDto> openMeetingList) {
openMeetingList.forEach(openMeeting -> {
List<String> subscribeStatisticalList = JSONArray.parseArray(openMeeting.getSubscribeStatistical(), String.class);
HashBag bag = new HashBag(subscribeStatisticalList);
int count = bag.getCount("0");
openMeeting.setTotal(count);
});
//第一种排序 (推荐使用)
Collections.sort(openMeetingList, new Comparator<MeetingInfoAndSubscribeInfoDto>() {
@Override
public int compare(MeetingInfoAndSubscribeInfoDto o1, MeetingInfoAndSubscribeInfoDto o2) {
int total1 = o1.getTotal();
int total2 = o2.getTotal();
//按倒序排序
return total2 - total1;
}
});
// 第二种排序
openMeetingList.stream().sorted(Comparator.comparing(MeetingInfoAndSubscribeInfoDto::getTotal).reversed()).collect(Collectors.toList());
}
Java 集合对象排序Collections
最新推荐文章于 2024-08-11 16:01:20 发布