Package java.util

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:
ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, 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 Details

    • AbstractSet

      protected AbstractSet()
      Constructs a new instance of this AbstractSet.
  • Method Details

    • equals

      public boolean equals​(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.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface Set<E>
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this set.
      Returns:
      true if the specified object is equal to this set, false otherwise
      See Also:
      hashCode()
    • 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.
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface Set<E>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this set.
      See Also:
      equals(java.lang.Object)
    • removeAll

      public boolean removeAll​(Collection<?> collection)
      Removes all occurrences in this collection which are contained in the specified collection.
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface Set<E>
      Overrides:
      removeAll in class AbstractCollection<E>
      Parameters:
      collection - the collection of objects to remove.
      Returns:
      true if this collection was modified, false otherwise.
      Throws:
      UnsupportedOperationException - if removing from this collection is not supported.