//排序
resultList = resultList.stream().sorted(Comparator.comparing(DynamicStockBean::getVESSEL_CD,Comparator.nullsLast(String::compareTo))
.thenComparing(DynamicStockBean::getVYG_NO,Comparator.nullsLast(Integer::compareTo))
.thenComparing(DynamicStockBean::getTYPE_SEQ,Comparator.nullsLast(Integer::compareTo))
.thenComparing(DynamicStockBean::getD_TM,Comparator.nullsLast(Timestamp::compareTo))
).collect(Collectors.toList());Comparator.comparing,thenComparing多属性排序,及空指针处理
最新推荐文章于 2026-06-20 02:33:04 发布
这段代码使用Java8的StreamAPI对DynamicStockBean列表进行排序,首先按VESSEL_CD(考虑null值在最后),然后按VYG_NO,接着是TYPE_SEQ,最后按D_TM(时间戳)进行排序,并将排序后的结果收集到新的列表中。

844

被折叠的 条评论
为什么被折叠?



