Class ConcurrentHashSet<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>

    public class ConcurrentHashSet<E>
    extends java.util.AbstractSet<E>
    implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable
    This class implements the Set interface, backed by a ConcurrentHashMap instance.
    Author:
    Matt Tucker
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentHashSet()
      Constructs a new, empty set; the backing ConcurrentHashMap instance has default initial capacity (16) and load factor (0.75).
      ConcurrentHashSet​(int initialCapacity)
      Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor, which is 0.75.
      ConcurrentHashSet​(int initialCapacity, float loadFactor)
      Constructs a new, empty set; the backing ConcurrentHashMap instance has the specified initial capacity and the specified load factor.
      ConcurrentHashSet​(java.util.Collection<? extends E> c)
      Constructs a new set containing the elements in the specified collection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E o)
      void clear()
      java.lang.Object clone()
      boolean contains​(java.lang.Object o)
      boolean isEmpty()
      java.util.Iterator<E> iterator()
      boolean remove​(java.lang.Object o)
      int size()
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        addAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArray
    • Constructor Detail

      • ConcurrentHashSet

        public ConcurrentHashSet()
        Constructs a new, empty set; the backing ConcurrentHashMap instance has default initial capacity (16) and load factor (0.75).
      • ConcurrentHashSet

        public ConcurrentHashSet​(java.util.Collection<? extends E> c)
        Constructs a new set containing the elements in the specified collection. The ConcurrentHashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.
        Parameters:
        c - the collection whose elements are to be placed into this set.
        Throws:
        java.lang.NullPointerException - if the specified collection is null.
      • ConcurrentHashSet

        public ConcurrentHashSet​(int initialCapacity,
                                 float loadFactor)
        Constructs a new, empty set; the backing ConcurrentHashMap instance has the specified initial capacity and the specified load factor.
        Parameters:
        initialCapacity - the initial capacity of the hash map.
        loadFactor - the load factor of the hash map.
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.
      • ConcurrentHashSet

        public ConcurrentHashSet​(int initialCapacity)
        Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor, which is 0.75.
        Parameters:
        initialCapacity - the initial capacity of the hash table.
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is less than zero.
    • Method Detail

      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.Set<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • add

        public boolean add​(E o)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException