Java ConcurrentHashMap keySet() Method21 Oct 2024 | 1 min read The keySet() method of ConcurrentHashMap class returns a Set view of the keys contained in this map. The set is stacked by the map, so changes to the map are reflected in the set, and vice-versa. SyntaxParameterNo parameter is passed. Returnsthe set view ThrowsNo Exception is thrown. Example 1Output: Map : {20=php, 10=Java, 11=.net, 12=C, 30=C++} keySet : [20, 10, 11, 12, 30] Example 2Output: Using KeySet : [A, B, C, D, E] enumeration of keys are: A B C D E Next TopicJava-concurrenthashmap-keys-method |
The computeIfPresent() method of ConcurrentHashMap class computes a new mapping given the key and its current mapped value If the value for the specified key is present. Syntax public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction) Parameter key - key with which the specified...
2 min read
The contains() method of ConcurrentHashMap class tests if some key maps into the specified value in this table. Syntax public boolean contains(Object value) Parameter value - a value to search for. Returns true if some key maps to the value argument in this table as determined by the equals method; false...
2 min read
The compute() method of ConcurrentHashMap class is used to compute the mapping for the specified key and its current value. Syntax public V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction) Parameter key - key with which the specified value is to be associated. remappingFunction...
3 min read
The forEach() method of ConcurrentHashMap class performs the given action for each key, value pair. Syntax public void forEach(long parallelismThreshold, BiConsumer<? super K,? super V> action) public <U> void forEach(long parallelismThreshold, BiFunction<? super K,? super V,? extends U> transformer, Consumer<? super U> action) Parameter parallelismThreshold - the (estimated) number of...
2 min read
The elements() method of ConcurrentHashMap class returns an enumeration of the values in this table. Syntax public Enumeration<v> elements() Parameter No parameter is passed. Returns an enumeration of the values in this table Throws NullPointerException Example 1 import java.util.*; import java.util.concurrent.*; public class ConcurrentHashMapelementsExample1 { public static...
2 min read
The entrySet() method of ConcurrentHashMap class returns a Set view of the mappings contained in this map. The changes made to the map are reflected in the set, and vice-versa. Syntax public Set<map.entry<k,v>> entrySet() Parameter No parameter is passed. Returns the set view Throws No exception is passed. Example 1 import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class ConcurrentHashMapentrySetExample1...
2 min read
The hashcode() method of ConcurrentHashMap class returns the hash code value for this Map, i.e., the sum of, for each key-value pair in the map, key.hashCode() ^ value.hashCode(). Syntax public int hashCode() Parameter No parameter is passed. Returns the hash code value for this map. Throws NullPointerException. Example 1 //import statement import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class ConcurrentHashMaphashcodeExample1...
2 min read
The containsKey() method of ConcurrentHashMap class tests if the specified object is a key in this table. Syntax public boolean containsKey(Object key) Parameter key - possible key Returns true if and only if the specified object is a key in this table, as determined by the equals method; false otherwise Throws NullPointerException...
2 min read
The remove() method of ConcurrentHashMap class removes the key (and its corresponding value) from this map. This method does nothing if the key is not on the map. Syntax public V remove(Object key) public boolean remove(Object key, Object value) Parameter key - the key that needs to be removed value -...
2 min read
The keys() method of ConcurrentHashMap class returns an enumeration of the keys in this table. Syntax public Enumeration<k> keys() Parameter No parameter is passed. Returns an enumeration of the keys in this table Throws No exception is thrown. Example 1 import java.util.*; import java.util.concurrent.*; public class ConcurrentHashMapKeysExample1 { public...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India