// 假设A和B是两个对象数组
List<Stu> A = new ArrayList<>();
List<Stu> B = new ArrayList<>();
// 使用 Stream API 进行筛选
List<Stu> collect = A.stream()
.filter(a -> !B.stream()
.anyMatch(b -> a.id().equals(b.id())))
.collect(Collectors.toList());
collect.forEach(choose -> {
...
})
【Java】Java 8 Stream通过filter()方法筛选出对象List不被另一个对象List包含的元素
最新推荐文章于 2024-04-27 09:13:51 发布