找出另一个数组列表中不存在的数组列表的元素 [英] find out the elements of an arraylist which is not present in another arraylist

查看:70
本文介绍了找出另一个数组列表中不存在的数组列表的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须找到一种最好的方法来找出没有出现在第二个数组列表中的元素.假设

I have to find a best way to find out that elements which is not presented in the second arraylist. suppose

Arraylist a,b, 

Arraylist a={1,2,3,4,5};
Arraylist b={2,3,4};

所以基本上我想要的是找出arraylist b中不存在的a元素.

So basically what I want is to find out that elements of a which is not present in arraylist b.

那么最好的解决方案是什么?

So what is the best solutions to do that?

推荐答案

List<Integer> c = new ArrayList<>(a);
c.removeAll(b);

还要考虑使用集合而不是列表.

Also consider to use Sets instead of Lists.

这篇关于找出另一个数组列表中不存在的数组列表的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆