Package java.util

Class HashSet<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
LinkedHashSet

public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, Serializable
HashSet is an implementation of a Set. All optional operations (adding and removing) are supported. The elements can be any objects.
See Also:
Serialized Form
  • Constructor Details

    • HashSet

      public HashSet()
      Constructs a new empty instance of HashSet.
    • HashSet

      public HashSet​(int capacity)
      Constructs a new instance of HashSet with the specified capacity.
      Parameters:
      capacity - the initial capacity of this HashSet.
    • HashSet

      public HashSet​(int capacity, float loadFactor)
      Constructs a new instance of HashSet with the specified capacity and load factor.
      Parameters:
      capacity - the initial capacity.
      loadFactor - the initial load factor.
    • HashSet

      public HashSet​(Collection<? extends E> collection)
      Constructs a new instance of HashSet containing the unique elements in the specified collection.
      Parameters:
      collection - the collection of elements to add.
  • Method Details