Java列表按照对象的属性去重并保持原有顺序
no bb 直接上代码,去重对象属性为nodeId
代码如下:
//去重合并
List<FlowNodeVo> datas = backNods.stream().collect(
Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(nodeVo -> nodeVo.getNodeId()))), ArrayList::new));
//排序
datas.sort(Comparator.comparing(FlowNodeVo::getEndTime));