注:
List<ForumPlateVo> list = new ArrayList<>();
list.add.......忽略一萬字
ForumPlateVo屬性:clickNum(點擊量)、replyNum(回覆量)、newReplyTime(最新回覆時間)、postNum(帖子量)
1、計算總量
(int)list.stream().mapToInt(n -> n.getClickNum()).summaryStatistics().getSum()
(int)list.stream().mapToInt(n -> n.getReplyNum()).summaryStatistics().getSum()
2、獲取最近時間
long date = list.stream().filter(x -> x!=null).filter(y -> y.getNewReplyTime()!=null).mapToLong(n -> n.getNewReplyTime().getTime()).summaryStatistics().getMax();
if(date>0) forumPlateVo.setNewReplyTime(new Date(date));
3、根據點擊量排序
list = list.stream().sorted(Comparator.comparing(ForumPlateVo::clickNum).reversed()).collect(Collectors.toList());
4、group by 獲取size
int count = list.stream().collect(groupingBy(ActivityLottery::getOpenId)).size();