使用stream实现根据id和时间最晚分组获取map

        Map<String, Attendance> collect = list.parallelStream().collect(Collectors.groupingBy(Attendance::getTokenid,
                        Collectors.collectingAndThen(
                                 Collectors.reducing((a,  b) -> a.getOpendate().getTime() > b.getOpendate().getTime() ? a : b), Optional::get)));

其中,Attendance是实体类,其两个字段分别是tokenId和openDate;

posted @ 2021-03-26 09:15  丙炎  阅读(242)  评论(0)    收藏  举报