java – 比较两个列表

我想比较两个列表.因为我们使用List编写接口,它不从Object类继承equals.我该怎么做呢?
即使List接口不包含equals方法,list-classes也可以(并且确实)实现equals方法.

API docs on AbstractList(由例如ArrayList,LinkedList,Vector继承):

public boolean equals(Object o)

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.

相关文章
相关标签/搜索