java stream有两个集合ListLong news和ListLong olds找出olds中存在但news中不存在的数据
可以使用Java 8的Stream API来解决这个问题。具体实现如下:
List<Long> news = ...; // 初始化news集合
List<Long> olds = ...; // 初始化olds集合
List<Long> result = olds.stream()
.filter(o -> !news.contains(o))
.collect(Collectors.toList());
上面的代码使用了Stream中的filter()方法来过滤出olds中存在但news中不存在的元素,最后使用collect()方法将这些元素收集到一个新的List中。
原文地址: https://www.cveoy.top/t/topic/g7cT 著作权归作者所有。请勿转载和采集!