WeakHashMap class Methods in Java

java.util.WeakHashMap

Hash table-based implementation of the Map interface, with weak keys. An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use.


Some methods of WeakHashMap class.


clear()This method removes all of the mappings from this map.


compute(K, BiFunction)This method attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).


computeIfAbsent(K, Function)If the specified key is not already associated with a value (or is mapped to null), attempt to compute its value using the given mapping function and enter it into this map unless null.


computeIfPresent(K, BiFunction)If the value for the specified key is present and non-null, attempt to compute a new mapping given the key and its current mapped value.


containsKey(Object)This method returns true if this map contains a mapping for the specified key.


containsValue(Object)This method returns true if this map maps one or more keys to the specified value.


entrySet()This method returns a Set view of the mappings contained in this map.


forEach(BiConsumer)This method performs the given action for each entry in this map until all entries have been processed or the action throws an exception.


get(Object)This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.


isEmpty()This method returns true if this map contains no key-value mappings.


keySet()This method returns a Set view of the keys contained in this map.


merge(K, V, BiFunction)If the specified key is not already associated with a value or is associated with null, associate it with the given non-null value.


put(K, V)This method associates the specified value with the specified key in this map.


putAll(Map)This method copies all of the mappings from the specified map to this map.


putIfAbsent(K, V)If the specified key is not already associated with a value associated with the given value and returns null, else returns the current value.


remove(Object)This method removes the mapping for a key from this weak hash map if it is present.


remove(Object, Object)This method removes the entry for the specified key only if it is currently mapped to the specified value.


replace(K, V)This method replaces the entry for the specified key only if it is currently mapped to some value.


replace(K, V, V)This method replaces the entry for the specified key only if currently mapped to the specified value.


replaceAll(BiFunction)This method replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.


size()This method returns the number of key-value mappings in this map.


values()This method returns a Collection view of the values contained in this map.


No comments:

Post a Comment