E - the type of element in the Setpublic class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Serializable
ConcurrentHashMap.| Constructor and Description |
|---|
ConcurrentHashSet()
Constructs a new, empty set.
|
ConcurrentHashSet(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.
|
ConcurrentHashSet(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75).
|
ConcurrentHashSet(int initialCapacity,
float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Adds the specified element to this set if it is not already present.
|
void |
clear()
Removes all of the elements from this set.
|
Object |
clone()
Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
|
boolean |
contains(Object o)
Returns true if this set contains the specified element.
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<E> |
iterator()
Returns an iterator over the elements in this set.
|
boolean |
remove(Object o)
Removes the specified element from this set if it is present.
|
int |
size()
Returns the number of elements in this set (its cardinality).
|
equals, hashCode, removeAlladdAll, containsAll, retainAll, toArray, toArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitaddAll, containsAll, equals, hashCode, removeAll, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic ConcurrentHashSet()
public ConcurrentHashSet(Collection<? extends E> c)
c - the collection whose elements are to be placed into this setNullPointerException - if the specified collection is nullpublic ConcurrentHashSet(int initialCapacity,
float loadFactor)
initialCapacity - the initial capacity of the hash maploadFactor - the load factor of the hash mapIllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositivepublic ConcurrentHashSet(int initialCapacity)
initialCapacity - the initial capacity of the hash tableIllegalArgumentException - if the initial capacity is less than zeropublic Iterator<E> iterator()
public int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>public boolean contains(Object o)
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>o - element whose presence in this set is to be testedpublic boolean add(E e)
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>e - element to be added to this setpublic boolean remove(Object o)
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>o - object to be removed from this set, if presentpublic void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>