Arraylist等于工作 [英] Arraylist Equals working
本文介绍了Arraylist等于工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
怀疑是否等于在Array List中工作的方法,下面的代码将其剪裁为true.
Have one doubt regard equals method working in Array List, Below code snip it print true.
ArrayList<String> s = new ArrayList<String>();
ArrayList<Integer> s1 = new ArrayList<Integer>();
System.out.println(s1.equals(s));
有人知道为什么要给出真实的答案吗?
Is any one have idea why it's giving true ans.
推荐答案
查看 equals() ArrayList
当且仅当指定对象也是一个列表,两个列表具有相同的大小,并且两个列表中所有对应的元素对相等时,才返回true.
Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.
由于没有元素,因此所有条件都得到满足,因此 true
.
Since there are no elements, all the conditions satisfied and hence true
.
如果将元素添加到两个列表中(每个元素中至少一个 ),则会看到所需的输出.
If you add elements to the both list (atleast one in each), to see the desired output.
这篇关于Arraylist等于工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文