public class ExtractIdUtils {
public static Map<String, List<Long>> extractList(List<Long> newIds, List<Long> oldIds) {
List<Long> tempList = new ArrayList<>(oldIds);
//取交集
tempList.retainAll(newIds);
//删除
oldIds.removeAll(tempList);
//新增
newIds.removeAll(tempList);
Map<String, List<Long>> extractMap = new HashMap<>();
extractMap.put("del", oldIds);
extractMap.put("add", newIds);
extractMap.put("update", tempList);
return extractMap;
}
public static void main(String[] args) {
ArrayList<Long> newIds = new ArrayList<>();
newIds.add(1L);
newIds.add(2L);
newIds.add(3L);
newIds.add(5L);
ArrayList<Long> oldIds = new ArrayList<>();
oldIds.add(1L);
oldIds.add(2L);
JAVA List 获取两个集合的交集 并集 差集
最新推荐文章于 2024-09-19 17:05:29 发布
本文介绍了如何使用JAVA操作List集合,详细讲解了获取两个List的交集、并集和差集的实现方式,包括使用Java 8的Stream API以及传统迭代方法,帮助开发者更高效地处理集合数据。
最低0.47元/天 解锁文章
2070

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



