【发布时间】:2021-01-24 12:23:20
【问题描述】:
我有两个:
registryId:1
registryID:1
registryID:2
最终列表应该是:我的意思是完全删除 1
registryID:2
我得到了这个解决方案:
List<TerpAccountListV> terpAccountListVFinal = compareUpdate(terpAccountListV, xxedgeAccountsListV);
Set<TerpAccountListV> set = terpAccountListVFinal.stream()
.collect(Collectors.toCollection(() -> new TreeSet()<>(Comparator.comparing(TerpAccountListV::getRegistryId))));
但是这会使 Single Set 具有注册表 ID。
如何在 Java 8 中使用这个集合从上面的列表中删除元素?
【问题讨论】:
-
.stream().distinct()呢? -
@VLAZ:不,它保留原始元素,就像在示例中我解释说我只需要 2 但应该完全使用 1。更新问题
标签: list lambda java-8 set comparator