E
-元素这一套保持型
public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E>
通过扩展这个类实现一组过程,通过扩展收集的实施收集相同,除了在该类的子类的方法和构造函数必须遵守的Set界面施加额外的限制(例如,添加方法不允许一个对象的多个实例集此外)。
注意这类不覆盖任何的实现从AbstractCollection类。它只是增加了equals和hashCode实现。
这个班的一员 Java Collections Framework。
Collection
,
AbstractCollection
,
Set
Modifier | Constructor and Description |
---|---|
protected |
AbstractSet()
唯一的构造函数。
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
将指定的对象与此设置的相等性进行比较。
|
int |
hashCode()
返回此组的哈希代码值。
|
boolean |
removeAll(Collection<?> c)
从这个集合中移除包含在指定集合中的所有元素(可选操作)。
|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, spliterator, toArray, toArray
parallelStream, removeIf, stream
public boolean equals(Object o)
实现首先检查指定对象是否是这套;如果它返回true。然后,检查指定的对象是否是一个大小相同的集合,如果不是,它返回假。如果是这样的话,它的回报containsAll((Collection) o)。
equals
接口
Collection<E>
equals
接口
Set<E>
equals
方法重写,继承类
Object
o
对象进行比较,用这套平等
Object.hashCode()
,
HashMap
public int hashCode()
Object.hashCode()
一般合同的要求。
这个实现遍历集合,调用hashCode方法对集合中的每个元素,并添加了结果。
hashCode
接口
Collection<E>
hashCode
接口
Set<E>
hashCode
方法重写,继承类
Object
Object.equals(Object)
,
Set.equals(Object)
public boolean removeAll(Collection<?> c)
这一决定实施这套较小和指定的集合,通过调用方法对每一size。如果set的元素更少,那么实现遍历这个集合,检查每个元素的迭代器返回的反过来看它是否包含在指定集合。如果是这样,包含的,正是从这一集的迭代器的remove法去除。如果指定集合的元素更少,那么实现遍历指定集合,从这个集合中的每个元素由迭代器返回的去除,使用这套方法的remove。
注意,这个实现会如果迭代器的iterator方法返回未实现remove方法抛出一个UnsupportedOperationException。
removeAll
接口
Collection<E>
removeAll
接口
Set<E>
removeAll
方法重写,继承类
AbstractCollection<E>
c
收集包含元素要从集合中移除
UnsupportedOperationException
-如果
removeAll操作set不支持
ClassCastException
-如果这个集合的元素的类与集合不相容(
optional)
NullPointerException
-如果这套包含一个null元素而指定集合不允许null元素(
optional),或者指定集合为空
AbstractCollection.remove(Object)
,
AbstractCollection.contains(Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.