Serializable, Iterable<K>, Collection<K>, Set<K>public static class ConcurrentHashMap.KeySetView<K,V> extends Object implements Set<K>, Collection<K>, Serializable
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).| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
add(K e) |
Adds the specified key to this set view by mapping the key to
the default mapped value in the backing map, if defined.
|
boolean |
addAll(Collection<? extends K> c) |
Adds all of the elements in the specified collection to this set,
as if by calling
add(K) on each one. |
void |
clear() |
Removes all of the elements from this view, by removing all
the mappings from the map backing this view.
|
boolean |
contains(Object o) |
Returns true if this set contains the specified element.
|
boolean |
containsAll(Collection<?> c) |
Returns true if this set contains all of the elements of the
specified collection.
|
boolean |
equals(Object o) |
Indicates whether some other object is "equal to" this one.
|
void |
forEach(Consumer<? super K> action) |
Performs the given action for each element of the
Iterable
until all elements have been processed or the action throws an
exception. |
ConcurrentHashMap<K,V> |
getMap() |
Returns the map backing this view.
|
V |
getMappedValue() |
Returns the default mapped value for additions,
or
null if additions are not supported. |
int |
hashCode() |
Returns a hash code value for the object.
|
boolean |
isEmpty() |
Returns true if this set contains no elements.
|
Iterator<K> |
iterator() |
Returns an iterator over the elements in this set.
|
boolean |
remove(Object o) |
Removes the key from this map view, by removing the key (and its
corresponding value) from the backing map.
|
boolean |
removeAll(Collection<?> c) |
Removes from this set all of its elements that are contained in the
specified collection (optional operation).
|
boolean |
retainAll(Collection<?> c) |
Retains only the elements in this set that are contained in the
specified collection (optional operation).
|
int |
size() |
Returns the number of elements in this set (its cardinality).
|
Spliterator<K> |
spliterator() |
Creates a
Spliterator over the elements in this set. |
Object[] |
toArray() |
Returns an array containing all of the elements in this set.
|
<T> T[] |
toArray(T[] a) |
Returns an array containing all of the elements in this set; the
runtime type of the returned array is that of the specified array.
|
String |
toString() |
Returns a string representation of this collection.
|
parallelStream, removeIf, streampublic V getMappedValue()
null if additions are not supported.null
if not supportedpublic boolean contains(Object o)
contains 在接口中 Collection<K>contains 在接口中 Set<K>o - element whose presence in this set is to be testedNullPointerException - if the specified key is nullpublic boolean remove(Object o)
remove 在接口中 Collection<K>remove 在接口中 Set<K>o - the key to be removed from the backing maptrue if the backing map contained the specified keyNullPointerException - if the specified key is nullpublic Iterator<K> iterator()
Setpublic boolean add(K e)
add 在接口中 Collection<K>add 在接口中 Set<K>e - key to be addedtrue if this set changed as a result of the callNullPointerException - if the specified key is nullUnsupportedOperationException - if no default mapped value
for additions was providedpublic boolean addAll(Collection<? extends K> c)
add(K) on each one.addAll 在接口中 Collection<K>addAll 在接口中 Set<K>c - the elements to be inserted into this settrue if this set changed as a result of the callNullPointerException - if the collection or any of its
elements are nullUnsupportedOperationException - if no default mapped value
for additions was providedSet.add(Object)public int hashCode()
ObjectHashMap.
The general contract of hashCode is:
hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode 在接口中 Collection<K>hashCode 在接口中 Set<K>hashCode 在类中 ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public boolean equals(Object o)
Object
The equals method implements an equivalence relation
on non-null object references:
x, x.equals(x) should return
true.
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.
x,
x.equals(null) should return false.
The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
equals 在接口中 Collection<K>equals 在接口中 Set<K>equals 在类中 Objecto - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
HashMappublic Spliterator<K> spliterator()
SetSpliterator over the elements in this set.
The Spliterator reports Spliterator#DISTINCT.
Implementations should document the reporting of additional
characteristic values.
spliterator 在接口中 Collection<K>spliterator 在接口中 Iterable<K>spliterator 在接口中 Set<K>Spliterator over the elements in this setpublic void forEach(Consumer<? super K> action)
IterableIterable
until all elements have been processed or the action throws an
exception. Unless otherwise specified by the implementing class,
actions are performed in the order of iteration (if an iteration order
is specified). Exceptions thrown by the action are relayed to the
caller.public final boolean removeAll(Collection<?> c)
SetremoveAll 在接口中 Collection<K>removeAll 在接口中 Set<K>c - collection containing elements to be removed from this setSet.remove(Object),
Set.contains(Object)public final int size()
Setpublic final boolean containsAll(Collection<?> c)
SetcontainsAll 在接口中 Collection<K>containsAll 在接口中 Set<K>c - collection to be checked for containment in this setSet.contains(Object)public final void clear()
public final boolean isEmpty()
Setpublic final Object[] toArray()
SetThe returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
public final <T> T[] toArray(T[] a)
SetIf this set fits in the specified array with room to spare (i.e., the array has more elements than this set), the element in the array immediately following the end of the set is set to null. (This is useful in determining the length of this set only if the caller knows that this set does not contain any null elements.)
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
Like the Set.toArray() method, this method acts as bridge between
array-based and collection-based APIs. Further, this method allows
precise control over the runtime type of the output array, and may,
under certain circumstances, be used to save allocation costs.
Suppose x is a set known to contain only strings. The following code can be used to dump the set into a newly allocated array of String:
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().toArray 在接口中 Collection<K>toArray 在接口中 Set<K>T - the runtime type of the array to contain the collectiona - the array into which the elements of this set are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.public final String toString()
"[]").
Adjacent elements are separated by the characters ", "
(comma and space). Elements are converted to strings as by
String#valueOf(Object).public ConcurrentHashMap<K,V> getMap()
public final boolean retainAll(Collection<?> c)
SetretainAll 在接口中 Collection<K>retainAll 在接口中 Set<K>c - collection containing elements to be retained in this setSet.remove(Object)