Compares the specified object with this list for equality. 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.
例如toString、hashCode方法等也是如此
正如@Pascal在注释中提到的,List接口提到了equals方法,并在文档中说明了以下内容:
The List interface places additional stipulations, beyond those specified in the Collection interface, on the contracts of the iterator, add, remove, equals, and hashCode methods.
# 1 楼答案
您仍然可以使用
equals
。所有对象都实现了它,您的列表仍然是对象,并根据需要覆盖equals
# 2 楼答案
从java中获得的默认行为。对象是“浅相等”。它将检查列表1和列表2是否是相同的引用:
如果您想要“deepequals”,请实例化扩展AbstractList的任何内容,例如ArrayList
# 3 楼答案
即使
List
接口不包含equals
方法,列表类也可以(并且确实)实现equals
方法从API docs on ^{} (例如
ArrayList
、LinkedList
、Vector
继承):例如
toString
、hashCode
方法等也是如此正如@Pascal在注释中提到的,List接口提到了
equals
方法,并在文档中说明了以下内容: