ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

数组对比去掉相同数据

2022-07-01 16:04:55  阅读:31  来源: 互联网

标签:ArrayList List two collect add 数组 new 去掉 对比


 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

专注分享技术,共同学习,共同进步。侵权联系[[email protected]]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有