Set
interface to minimize the effort required to implement this
interface.
The process of implementing a set by extending this class is identical
to that of implementing a Collection by extending AbstractCollection,
except that all of the methods and constructors in subclasses of this
class must obey the additional constraints imposed by the Set
interface (for instance, the add method must not permit addition of
multiple instances of an object to a set).
Note that this class does not override any of the implementations from
the AbstractCollection
class. It merely adds implementations
for equals
and hashCode
.
This class is a member of the Java Collections Framework.
Collection
, AbstractCollection
, Set
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if the specified object is equal to this setobject to be compared for equality with this set o)Overrides java. Implements java. Compares the specified object with this set for equality. |
public int | Returns: the hash code value for this setOverrides java. Implements java. Returns the hash code value for this set. |
public boolean | Returns: true if this set changed as a result of the callcollection containing elements to be removed from this set c)Overrides java. Implements java. Removes from this set all of its elements that are contained in the specified collection (optional operation). |
AbstractSet | back to summary |
---|---|
protected AbstractSet() Sole constructor. (For invocation by subclass constructors, typically implicit.) |
equals | back to summary |
---|---|
public boolean equals(Object o) Overrides java. Implements java. Compares the specified object with this set for equality. Returns
This implementation first checks if the specified object is this
set; if so it returns
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Implements java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a This implementation iterates over the set, calling the
|
removeAll | back to summary |
---|---|
public boolean removeAll(Collection<?> c) Overrides java. Implements java. Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets. This implementation determines which is the smaller of this set
and the specified collection, by invoking the Note that this implementation will throw an
|