# Class AbstractSet<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>

All Implemented Interfaces:
  `Iterable<E>, Collection<E>, Set<E>`

Direct Known Subclasses:
  `HashSet, TreeSet`

public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E>

An AbstractSet is an abstract implementation of the Set interface. This implementation does not support adding. A subclass must implement the abstract methods iterator() and size().

##### Since

1.2

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractSet()`
  Constructs a new instance of this AbstractSet.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(java.lang.Object object)`
  Compares the specified object to this Set and returns true if they are equal.
  `int`
  `hashCode()`
  Returns the hash code for this set.
  `boolean`
  `removeAll(Collection<?> collection)`
  Removes all occurrences in this collection which are contained in the specified collection.

  ### Methods inherited from class AbstractCollection

  `add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Collection

  `removeIf`

  ### Methods inherited from interface Iterable

  `forEach`

  ### Methods inherited from interface Set

  `add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray`

- ## Constructor Details

  - ### AbstractSet

    protected AbstractSet()
    Constructs a new instance of this AbstractSet.

- ## Method Details

  - ### equals

    public boolean equals(java.lang.Object object)

    Compares the specified object to this Set and returns true if they are equal. The object must be an instance of Set and contain the same objects.

    ###### Parameters

    - `object`: the object to compare with this set.

    ###### Returns

    Specified by:
      `equals` in interface `Collection<E>`
    Specified by:
      `equals` in interface `Set<E>`
    Overrides:
      `equals` in class `java.lang.Object`
    Returns:

      `true` if the specified object is equal to this set, `false` otherwise

      ###### See also

      - #hashCode

  - public int hashCode()

    Returns the hash code for this set. Two set which are equal must return the same value. This implementation calculates the hash code by adding each element's hash code.

    ###### Returns

    the hash code of this set.

    ###### See also

    - #equals
    Specified by:
      `hashCode` in interface `Collection<E>`
    Specified by:
      `hashCode` in interface `Set<E>`
    Overrides:
      `hashCode` in class `java.lang.Object`

  - ### removeAll

    public boolean removeAll(Collection<?> collection)

    Removes all occurrences in this collection which are contained in the specified collection.

    ###### Parameters

    - `collection`: the collection of objects to remove.

    ###### Returns

    Specified by:
      `removeAll` in interface `Collection<E>`
    Specified by:
      `removeAll` in interface `Set<E>`
    Overrides:
      `removeAll` in class `AbstractCollection<E>`
    Returns:

      `true` if this collection was modified, `false` otherwise.

      ###### Throws

      - `UnsupportedOperationException`: if removing from this collection is not supported.