HashSet'在检查元素之前是否containsAll()会比较集合大小?
1652 次
1 回答
5
HashSetextendsAbstractSet依次扩展AbstractCollection(定义containsAll方法)。你可以在AbstractCollection 这里找到源代码。您会发现containsAll(第 292 行)实现为:
public boolean containsAll(Collection<?> c) {
Iterator<?> e = c.iterator();
while (e.hasNext())
if (!contains(e.next()))
return false;
return true;
}
所以不,没有比较集合大小。
于 2013-08-04T15:54:26.433 回答