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-05-21 11:05:53 发布