map求差集

875 阅读1分钟

stream方式

    public static void main (String args[]){
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put(1,1);
        hashMap.put(2,2);
        HashMap<Object, Object> hashMap2 = new HashMap<>();
        hashMap2.put(1,1);
        System.out.println(hashMap.keySet().stream().filter(k -> !hashMap2.containsKey(k))
                .collect(Collectors.toList()));
    }

输出结果:

image.png