ArrayList包含另一个ArrayList [英] ArrayList contains another ArrayList
本文介绍了ArrayList包含另一个ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个简单的单线程,我只是不在这里,但这是我的问题:
There is probably a simple one-liner that I am just not finding here, but this is my question:
如何检查一个ArrayList是否包含所有的对象在另一个ArrayList中。我正在寻找(如果存在)沿着以下行:
How to check if an ArrayList contains all of the objects in another ArrayList. I am looking (if it exists) for something along the lines of:
//INCORRECT EXAMPLE:
if(one.contains(two))
{
return true;
}
else
{
return false;
}
例如:
ArrayList one = {1, 2, 3, 4, 5}
ArrayList two = {1, 2, 3} --> True
ArrayList two = {} --> True
ArrayList two = {1, 2, 3, 4, 5} --> True
ArrayList two = {1, 5, 2} --> True
ArrayList two = {1, 7, 4} --> False
ArrayList two = {0, 1, 3} --> False
ArrayList two = {4, 5, 6} --> False
ArrayList two = {7, 8, 9} --> False
推荐答案
有一个方法 contains c> c> c> c。在您的设置
one.containsAll(two)
给出所需的答案。
There is a method called containsAll
declared in the java.util.Collection
interface. In your setting one.containsAll(two)
gives the desired answer.
这篇关于ArrayList包含另一个ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文