mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.panzhihua.common.utlis;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Author: llming
 * @Description: 获取不同两个list不同元素
 */
public class DifferentLongListUtil {
    public static List<Long> getDiffrent(List<Long> list1, List<Long> list2) {
        Map<Long, Integer> map = new HashMap<Long, Integer>(list1.size() + list2.size());
        List<Long> diff = new ArrayList<Long>();
        List<Long> maxList = list1;
        List<Long> minList = list2;
        if (list2.size() > list1.size()) {
            maxList = list2;
            minList = list1;
        }
 
        for (Long Long : maxList) {
            map.put(Long, 1);
        }
 
        for (Long Long : minList) {
            Integer cc = map.get(Long);
            if (cc != null) {
                map.put(Long, ++cc);
                continue;
            }
            map.put(Long, 1);
        }
 
        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            if (entry.getValue() == 1) {
                diff.add(entry.getKey());
            }
        }
        return diff;
    }
 
    public static void main(Long[] args) {
        // List<Long> Longs1 = Arrays.asList(1L, 2L, 2L, 3L, 4L);
        // List<Long> Longs2 = Arrays.asList(1L, 2L, 5L, 6L, 4L);
        // List<Long> diffrent = getDiffrent(Longs1, Longs2);
        // System.out.println(diffrent);
    }
}