作者:可爱鼠标1985 | 来源:互联网 | 2023-05-18 16:34
I have an ArrayList
, and I add an array to it.
我有一个ArrayList
,我给它添加了一个数组。
ArrayList j = new ArrayList();
int[] w = {1,2};
j.add(w);
Suppose I want to know if j
contains an array that has {1,2}
in it without using w
, since I will be calling it from another class. So, I create a new array with {1,2}
in it...
假设我想知道j是否包含一个包含{1,2}且不使用w的数组,因为我将从另一个类调用它。因此,我创建了一个包含{1,2}的新数组…
int[] t = {1,2};
return j.contains(t);
...but this would return false even though w
was added to the list, and w
contains the exact same array as t
.
…但这将返回false,尽管w被添加到列表中,而w包含与t相同的数组。
Is there a way to use contains such that I can just check to see if one of the elements of the ArrayList
has the array value {1,2}
?
是否有一种方法可以使用contains,我可以检查ArrayList的一个元素是否具有数组值{1,2}?
7 个解决方案