当你调用卸下一个ArrayList(对象o),它是如何比较对象? [英] When you call remove(object o) on an arraylist, how does it compare objects?
问题描述
当你打电话取消对在java中一个ArrayList(对象o),它是如何比较的对象找到正确的去除?它使用指针?或者它使用接口可比比较的对象?
When you call remove(object o) on an arraylist in java, how does it compare the objects to find the correct one to remove? does it use the pointer? or does it compare the objects using the interface Comparable?
推荐答案
的ArrayList remove()方法依赖于对象实现平等的方法。如果没有执行已完成,然后该目的通过对象的实现的Equals这的确是指针比较移除。
ArrayList remove() relies on the objects implementation of the Equal method. If no implementation has been done then the object is removed by Object's implementation of Equals which indeed is the pointer comparison.
从上ArrayList中的文件 -
From the documentation on ArrayList -
更确切地讲,移除具有索引i的元素(O == NULL得到(I)== NULL:o.equals(获得(I)))(如果这样的元素存在)
对象相等方法的文档 -
Object equal method documentation -
Object类的equals方法实现对象上差别可能性最大的相等关系;也就是说,对于任何非空引用值x和y,这种方法当且仅当x和y指的是同一个对象,则返回true(X == y具有的值真)。
这篇关于当你调用卸下一个ArrayList(对象o),它是如何比较对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!