T
- the type of the set objects@ThreadSafe public final class ConcurrentHashSet<T> extends AbstractSet<T>
ConcurrentHashMap
, and Set
operations are translated to ConcurrentHashMap
operations.Constructor and Description |
---|
ConcurrentHashSet()
Creates a new
ConcurrentHashSet . |
ConcurrentHashSet(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Creates a new
ConcurrentHashSet . |
Modifier and Type | Method and Description |
---|---|
boolean |
add(T element) |
boolean |
addIfAbsent(T element)
Adds an element into the set, if and only if it is not already a part of the set.
|
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
isEmpty() |
Iterator<T> |
iterator() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
Object[] |
toArray() |
<E> E[] |
toArray(E[] a) |
String |
toString() |
equals, hashCode
addAll
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, spliterator
parallelStream, removeIf, stream
public ConcurrentHashSet()
ConcurrentHashSet
.public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel)
ConcurrentHashSet
.initialCapacity
- the initial capacityloadFactor
- the load factor threshold, used to control resizingconcurrencyLevel
- the estimated number of concurrently updating threadspublic int size()
size
in interface Collection<T>
size
in interface Set<T>
size
in class AbstractCollection<T>
public boolean add(T element)
add
in interface Collection<T>
add
in interface Set<T>
add
in class AbstractCollection<T>
public boolean addIfAbsent(T element)
element
- the element to add into the setpublic void clear()
clear
in interface Collection<T>
clear
in interface Set<T>
clear
in class AbstractCollection<T>
public boolean contains(Object o)
contains
in interface Collection<T>
contains
in interface Set<T>
contains
in class AbstractCollection<T>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<T>
containsAll
in interface Set<T>
containsAll
in class AbstractCollection<T>
public boolean isEmpty()
isEmpty
in interface Collection<T>
isEmpty
in interface Set<T>
isEmpty
in class AbstractCollection<T>
public boolean remove(Object o)
remove
in interface Collection<T>
remove
in interface Set<T>
remove
in class AbstractCollection<T>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<T>
removeAll
in interface Set<T>
removeAll
in class AbstractSet<T>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<T>
retainAll
in interface Set<T>
retainAll
in class AbstractCollection<T>
public Object[] toArray()
toArray
in interface Collection<T>
toArray
in interface Set<T>
toArray
in class AbstractCollection<T>
public <E> E[] toArray(E[] a)
toArray
in interface Collection<T>
toArray
in interface Set<T>
toArray
in class AbstractCollection<T>
public String toString()
toString
in class AbstractCollection<T>
Copyright © 2023. All Rights Reserved.