java.lang.Object
java.util.concurrent.ConcurrentHashMap.KeySetView<K,V>
- All Implemented Interfaces:
Serializable,Iterable<K>,Collection<K>,Set<K>
- Enclosing class:
ConcurrentHashMap<K,V>
public static class ConcurrentHashMap.KeySetView<K,V>
extends Object
implements Set<K>, Serializable
A view of a ConcurrentHashMap as a
Set of keys, in
which additions may optionally be enabled by mapping to a
common value. This class cannot be directly instantiated.
See keySet(),
keySet(V),
newKeySet(),
newKeySet(int).- Since:
- 1.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified key to this set view by mapping the key to the default mapped value in the backing map, if defined.booleanaddAll(Collection<? extends K> c) Adds all of the elements in the specified collection to this set, as if by callingadd(K)on each one.final voidclear()Removes all of the elements from this view, by removing all the mappings from the map backing this view.booleanfinal booleancontainsAll(Collection<?> c) booleangetMap()Returns the map backing this view.Returns the default mapped value for additions, ornullif additions are not supported.inthashCode()final booleanisEmpty()iterator()Returns an iterator over the elements in this collection.booleanRemoves the key from this map view, by removing the key (and its corresponding value) from the backing map.booleanremoveAll(Collection<?> c) final booleanretainAll(Collection<?> c) final intsize()final Object[]toArray()final <T> T[]toArray(T[] a) final StringtoString()Returns a string representation of this collection.Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods declared in interface java.util.Set
clear, containsAll, isEmpty, removeAll, retainAll, size, spliterator, toArray, toArray
-
Method Details
-
getMappedValue
Returns the default mapped value for additions, ornullif additions are not supported.- Returns:
- the default mapped value for additions, or
nullif not supported
-
contains
- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Throws:
NullPointerException- if the specified key is null
-
remove
Removes the key from this map view, by removing the key (and its corresponding value) from the backing map. This method does nothing if the key is not in the map.- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Parameters:
o- the key to be removed from the backing map- Returns:
trueif the backing map contained the specified key- Throws:
NullPointerException- if the specified key is null
-
iterator
Returns an iterator over the elements in this collection.The returned iterator is weakly consistent.
-
add
Adds the specified key to this set view by mapping the key to the default mapped value in the backing map, if defined.- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Parameters:
e- key to be added- Returns:
trueif this set changed as a result of the call- Throws:
NullPointerException- if the specified key is nullUnsupportedOperationException- if no default mapped value for additions was provided
-
addAll
Adds all of the elements in the specified collection to this set, as if by callingadd(K)on each one.- Specified by:
addAllin interfaceCollection<K>- Specified by:
addAllin interfaceSet<K>- Parameters:
c- the elements to be inserted into this set- Returns:
trueif this set changed as a result of the call- Throws:
NullPointerException- if the collection or any of its elements arenullUnsupportedOperationException- if no default mapped value for additions was provided
-
hashCode
public int hashCode() -
equals
-
getMap
Returns the map backing this view.- Returns:
- the map backing this view
-
clear
public final void clear()Removes all of the elements from this view, by removing all the mappings from the map backing this view.- Specified by:
clearin interfaceCollection<K>
-
size
public final int size()- Specified by:
sizein interfaceCollection<K>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<K>
-
toArray
- Specified by:
toArrayin interfaceCollection<K>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<K>
-
toString
Returns a string representation of this collection. The string representation consists of the string representations of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters", "(comma and space). Elements are converted to strings as byString.valueOf(Object). -
containsAll
- Specified by:
containsAllin interfaceCollection<K>
-
removeAll
- Specified by:
removeAllin interfaceCollection<K>
-
retainAll
- Specified by:
retainAllin interfaceCollection<K>
-