ArrayList包含另一个的ArrayList [英] ArrayList contains another ArrayList

查看:153
本文介绍了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

谢谢!

推荐答案

containsAll 中声明称法 java.util.Collection中接口。在您的设置 one.containsAll(二)得到所需的答案。

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屋!

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