ConcurrentHashMap keys() method in Java with Examples Last Updated : 30 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The keys() method of ConcurrentHashMap class in Java is used to get the enumeration of the keys present in the hashmap. Syntax: Enumeration enu = ConcurrentHashMap.keys() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the keys of the ConcurrentHashMap. Below programs are used to illustrate the working of the keys() method: Program 1: Java // Java code to illustrate the keys() method import java.util.*; import java.util.concurrent.*; public class ConcurrentHashMapDemo { public static void main(String[] args) { // Creating an empty ConcurrentHashMap ConcurrentHashMap<Integer, String> hash_map = new ConcurrentHashMap<Integer, String>(); // Inserting elements into the map hash_map.put(10, "Geeks"); hash_map.put(15, "4"); hash_map.put(20, "Geeks"); hash_map.put(25, "Welcomes"); hash_map.put(30, "You"); // Displaying the ConcurrentHashMap System.out.println("The Map is: " + hash_map); // Creating an empty enumeration to store Enumeration enu = hash_map.keys(); System.out.println("The enumeration of keys are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } Output: The Map is: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4} The enumeration of keys are: 20 25 10 30 15 Program 2: Java // Java code to illustrate the keys() method import java.util.*; import java.util.concurrent.*; public class ConcurrentHashMapDemo { public static void main(String[] args) { // Creating an empty ConcurrentHashMap ConcurrentHashMap<String, Integer> hash_map = new ConcurrentHashMap<String, Integer>(); // Inserting elements into the table hash_map.put("Geeks", 10); hash_map.put("4", 15); hash_map.put("Geeks", 20); hash_map.put("Welcomes", 25); hash_map.put("You", 30); // Displaying the ConcurrentHashMap System.out.println("The Map is: " + hash_map); // Creating an empty enumeration to store Enumeration enu = hash_map.keys(); System.out.println("The enumeration of keys are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } Output: The Map is: {4=15, Geeks=20, You=30, Welcomes=25} The enumeration of keys are: 4 Geeks You Welcomes Comment More infoAdvertise with us Next Article ConcurrentHashMap keys() method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java-Functions Java-ConcurrentHashMap Practice Tags : JavaMisc Similar Reads ConcurrentHashMap in Java In Java, the ConcurrentHashMap is a thread-safe implementation of the Map interface. It allows multiple threads to read and write data simultaneously, without the need for locking the entire map. Unlike a regular HashMap, which is not thread-safe, ConcurrentHashMap ensures that the operations are th 15+ min read Java ConcurrentHashMap | clear() The clear() method in Java's ConcurrentHashMap class is used to remove all the key-value pairs from the map. It has the following signature: The clear() method works in a concurrent environment, which means that it can be called from multiple threads without causing any data race or synchronization 3 min read ConcurrentHashMap compute() method in Java with Examples The compute(Key, BiFunction) method of ConcurrentHashMap class is used to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping is found). This method is used to atomically update a value for given key in ConcurrentHashMap.If the remapping funct 3 min read ConcurrentHashMap computeIfAbsent() method in Java with Examples The computeIfAbsent(Key, Function) method of ConcurrentHashMap class which attempts to compute its value using the given mapping function for specified key if key is not already associated with a value (or is mapped to null) and enter that computed value in map else null. If mapping function of this 3 min read ConcurrentHashMap contains() method in Java with Examples The contains() method of Java.util.ConcurrentHashMap is used to check whether if some key maps into the specified value in this table. It is a legacy method of performing a particular task. The operation is similar to containsValue() Method of ConcurrentHashMap. Syntax: ConcurrentHashMap.contains(Ob 2 min read ConcurrentHashMap containsKey() Method in Java The containsKey() method in Java's ConcurrentHashMap class is used to determine whether the map contains a given key. It has the following signature: boolean containsKey(Object key) where: key is the key to be searched for in the map. The containsKey() method works in a concurrent environment, which 3 min read ConcurrentHashMap containsValue() Method in Java The containsValue() method in Java's ConcurrentHashMap class is used to determine whether the map contains a given value. It has the following signature: boolean containsValue(Object value) where: value is the value to be searched for in the map.The containsValue() method works in a concurrent envir 3 min read ConcurrentHashMap elements() method in Java with Examples The elements() method of ConcurrentHashMap class in Java is used to get the enumeration of the values present in the table. Syntax: Enumeration enu = ConcurrentHashMap.elements() Parameters: The method does not take any parameters. Return value: The method returns an enumeration of the values of the 2 min read ConcurrentHashMap entrySet() method in Java with Examples The entrySet() method of ConcurrentHashMap in Java is used to create a set from the same elements contained in the concurrent hash map. It basically returns a set view of the concurrent hash map or we can create a new set and store the map elements into them. Syntax: ConcurrentHashMap.entrySet() Par 2 min read ConcurrentHashMap get() Method in Java The get() method in Java's ConcurrentHashMap class is used to retrieve the value associated with a given key. It has the following signature: V get(Object key) where: key is the key whose associated value is to be retrieved.The get() method works in a concurrent environment, which means that it can 3 min read Like