数组对比去掉相同数据

 public static void main(String[] args) {
        List<String> one = new ArrayList<>();

        one.add("jim");

        one.add("tom");

        one.add("jack");

// 集合二

        List<String> two = new ArrayList<>();

        two.add("jim");

        two.add("tom");

        two.add("jack");

        two.add("good");

        Collection exists=new ArrayList(two);

        Collection notexists=new ArrayList(two);

        exists.removeAll(one);

        List<String> collect = two.stream().filter(v -> one.stream().allMatch(x -> (!v.equals(x)))).collect(Collectors.toList());
        System.out.println(collect);
    }

结果如图

 

posted @ 2022-07-01 15:58  未来可期丶May  阅读(53)  评论(0)    收藏  举报
Live2d Test Env