list过滤对象之时间比较

时间比较--比如过滤超过1年的数据  用 Integer值比较

String local = LocalDate.now().toString().replaceAll("-", "").substring(0, 6);// 202507
Integer localYearMonth = Integer.valueOf(local);
boolean b = Objects.nonNull(xxx);

List<XXX> collect = strings.stream().filter(xxx-> Objects.nonNull(xxx))
.filter(a -> (Math.abs(Integer.valueOf(a.getYearMonth()) - localYearMonth)) <= 100)
.collect(Collectors.toList());
// 时间分表
Map<String, List<XXXX>> byMonth = collectByTime.stream().collect(Collectors.groupingBy(XXXXX::getMsgMonth));

posted on 2023-07-19 22:47  daofree  阅读(184)  评论(0编辑  收藏  举报