This is a Java program that demonstrates how to check if a HashMap is empty or not. Here's how it works:
import java.util.*; public class Check_EmptyNot { public static void main(String args[]) { HashMap <Integer,String> hash_map = new HashMap <Integer,String> (); hash_map.put(1, "Pink"); hash_map.put(2, "Green"); hash_map.put(3, "Red"); hash_map.put(4, "White"); hash_map.put(5, "Blue"); hash_map.put(6, "Black"); hash_map.put(7, "Orange"); boolean res = hash_map.isEmpty(); System.out.println("Is Hashmap Empty : " + res); hash_map.clear(); res = hash_map.isEmpty();// check if map is empty System.out.println("Is Hashmap Empty : " + res); } }
Is Hashmap Empty : false Is Hashmap Empty : true
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions