size(): This method is available in java.util.WeakHashMap class of Java.
Syntax:
int java.util.WeakHashMap.size()
This method returns the number of key-value mappings in this map.
Parameters: NA
Returns: the number of key-value mappings in this map.
Exceptions: NA
Approach
Java
import java.util.WeakHashMap;public class WeakHashMapsize {public static void main(String[] args) {WeakHashMap<String, String> weakHashMap =new WeakHashMap<String, String>();weakHashMap.put("Java", "Program");weakHashMap.put("Hello", "World");System.out.println(weakHashMap.size());}}
Output:
2
No comments:
Post a Comment