ConcurrentHashMap size() Method in Java
The java.util.concurrent.ConcurrentHashMap.size() method is an in-built function in Java which counts the number of key-value mappings in this map and returns the integer value.
Syntax:
public int size()
Return Value: The function returns an integer value which denotes the number of key-value mappings in this map.
Below program illustrate the use of size() method :
Program 1:
// Java Program Demonstrate size() // method of ConcurrentHashMap import java.util.concurrent.*; class GFG { public static void main(String[] args) { ConcurrentHashMap<Integer, String> chm = new ConcurrentHashMap<Integer, String>(); chm.put(100, "Geeks"); chm.put(101, "for"); chm.put(102, "Geeks"); // Display the number of // key-value mappings System.out.println("The number of " + "key-value mappings is " + chm.size()); } } |
The number of key-value mappings is 3
Program 2:
// Java Program Demonstrate size() // method of ConcurrentHashMap import java.util.concurrent.*; class GFG { public static void main(String[] args) { ConcurrentHashMap<Integer, Integer> chm = new ConcurrentHashMap<Integer, Integer>(); chm.put(1, 100); chm.put(2, 200); chm.put(3, 300); chm.put(4, 400); chm.put(5, 500); chm.put(6, 600); // Display the number of // key-value mappings System.out.println("The number of " + "key-value mappings is " + chm.size()); } } |
The number of key-value mappings is 6
Reference : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html#size()
Recommended Posts:
- ConcurrentHashMap put() method in Java
- ConcurrentHashMap get() Method in Java
- ConcurrentHashMap contains() method in Java with Examples
- ConcurrentHashMap isEmpty() Method in Java
- ConcurrentHashMap remove() method in Java
- ConcurrentHashMap putAll() method in Java
- ConcurrentHashMap putIfAbsent() Method in Java
- ConcurrentHashMap containsKey() Method in Java
- ConcurrentHashMap containsValue() Method in Java
- ConcurrentHashMap values() method in Java with Examples
- ConcurrentHashMap keys() method in Java with Examples
- ConcurrentHashMap elements() method in Java with Examples
- ConcurrentHashMap entrySet() method in Java with Examples
- ConcurrentHashMap computeIfAbsent() method in Java with Examples
- ConcurrentHashMap compute() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



