其他分享
首页 > 其他分享> > 数组对比去掉相同数据

数组对比去掉相同数据

作者:互联网

 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);
    }

结果如图

 

标签:ArrayList,List,two,collect,add,数组,new,去掉,对比
来源: https://www.cnblogs.com/October-28/p/16434969.html