- Type Parameters:
- K- the type of keys
- V- the type of values in the backing map
- All Implemented Interfaces:
- Serializable,- Iterable<K>,- Collection<K>,- Set<K>
- Enclosing class:
- ConcurrentHashMap<K,- V> 
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 SummaryModifier 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.booleanReturnstrueif this collection contains the specified element.final booleancontainsAll(Collection<?> c) Returnstrueif this collection contains all of the elements in the specified collection.booleanIndicates whether some other object is "equal to" this one.getMap()Returns the map backing this view.Returns the default mapped value for additions, ornullif additions are not supported.inthashCode()Returns a hash code value for the object.final booleanisEmpty()Returnstrueif this collection contains no elements.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) Removes all of this collection's elements that are also contained in the specified collection (optional operation).final booleanretainAll(Collection<?> c) Retains only the elements in this collection that are contained in the specified collection (optional operation).final intsize()Returns the number of elements in this collection.final Object[]toArray()Returns an array containing all of the elements in this collection.final <T> T[]toArray(T[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.final StringtoString()Returns a string representation of this collection.Methods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods declared in interface java.util.Setclear, containsAll, isEmpty, removeAll, retainAll, size, spliterator, toArray, toArray
- 
Method Details- 
getMappedValueReturns the default mapped value for additions, ornullif additions are not supported.- Returns:
- the default mapped value for additions, or nullif not supported
 
- 
containsReturnstrueif this collection contains the specified element. More formally, returnstrueif and only if this collection contains at least one elementesuch thatObjects.equals(o, e).- Specified by:
- containsin interface- Collection<K>
- Specified by:
- containsin interface- Set<K>
- Parameters:
- o- element whose presence in this collection is to be tested
- Returns:
- trueif this collection contains the specified element
- Throws:
- NullPointerException- if the specified key is null
 
- 
removeRemoves 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 interface- Collection<K>
- Specified by:
- removein interface- Set<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
 
- 
iteratorReturns an iterator over the elements in this collection.The returned iterator is weakly consistent. 
- 
addAdds 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 interface- Collection<K>
- Specified by:
- addin interface- Set<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 null
- UnsupportedOperationException- if no default mapped value for additions was provided
 
- 
addAllAdds all of the elements in the specified collection to this set, as if by callingadd(K)on each one.- Specified by:
- addAllin interface- Collection<K>
- Specified by:
- addAllin interface- Set<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 are- null
- UnsupportedOperationException- if no default mapped value for additions was provided
- See Also:
 
- 
hashCodepublic int hashCode()Description copied from class:ObjectReturns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of hashCodeis:- Whenever it is invoked on the same object more than once during
     an execution of a Java application, the hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the equalsmethod, then calling thehashCodemethod on each of the two objects must produce the same integer result.
- It is not required that if two objects are unequal
     according to the equalsmethod, then calling thehashCodemethod 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.
 
- Whenever it is invoked on the same object more than once during
     an execution of a Java application, the 
- 
equalsDescription copied from class:ObjectIndicates whether some other object is "equal to" this one.The equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
     x,x.equals(x)should returntrue.
- It is symmetric: for any non-null reference values
     xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue.
- It is transitive: for any non-null reference values
     x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue.
- It is consistent: for any non-null reference values
     xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified.
- For any non-null reference value x,x.equals(null)should returnfalse.
 An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. 
- It is reflexive: for any non-null reference value
     
- 
getMapReturns the map backing this view.- Returns:
- the map backing this view
 
- 
clearpublic 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 interface- Collection<K>
 
- 
sizepublic final int size()Description copied from interface:CollectionReturns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
- sizein interface- Collection<K>
- Returns:
- the number of elements in this collection
 
- 
isEmptypublic final boolean isEmpty()Description copied from interface:CollectionReturnstrueif this collection contains no elements.- Specified by:
- isEmptyin interface- Collection<K>
- Returns:
- trueif this collection contains no elements
 
- 
toArrayDescription copied from interface:CollectionReturns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's runtime component type isObject.The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array. - Specified by:
- toArrayin interface- Collection<K>
- Returns:
- an array, whose runtime component
 type is Object, containing all of the elements in this collection
 
- 
toArraypublic final <T> T[] toArray(T[] a) Description copied from interface:CollectionReturns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain anynullelements.)If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. - Specified by:
- toArrayin interface- Collection<K>
- Type Parameters:
- T- the component type of the array to contain the collection
- Parameters:
- a- the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
- Returns:
- an array containing all of the elements in this collection
 
- 
toStringReturns 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).
- 
containsAllDescription copied from interface:CollectionReturnstrueif this collection contains all of the elements in the specified collection.- Specified by:
- containsAllin interface- Collection<K>
- Parameters:
- c- collection to be checked for containment in this collection
- Returns:
- trueif this collection contains all of the elements in the specified collection
- See Also:
 
- 
removeAllDescription copied from interface:CollectionRemoves all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.- Specified by:
- removeAllin interface- Collection<K>
- Parameters:
- c- collection containing elements to be removed from this collection
- Returns:
- trueif this collection changed as a result of the call
- See Also:
 
- 
retainAllDescription copied from interface:CollectionRetains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.- Specified by:
- retainAllin interface- Collection<K>
- Parameters:
- c- collection containing elements to be retained in this collection
- Returns:
- trueif this collection changed as a result of the call
- See Also:
 
 
-