This is a Java program that demonstrates how to count the number of key-value pairs in a HashMap. Here's how it works:
import java.util.*; public class CountNum_KeyValue { public static void main(String args[]) { HashMap<Integer,String> hash_map = new HashMap<Integer,String>(); hash_map.put(1, "Cherry"); hash_map.put(2, "Banana"); hash_map.put(3, "Apple"); hash_map.put(4, "Mango"); hash_map.put(5, "Guava"); System.out.println("Count Number of Key-Value in HashMap : "+hash_map.size()); } }
Count Number of Key-Value in HashMap : 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions