This is a Java program that demonstrates how to remove all elements from a HashMap. Here's how it works:
import java.util.*; public class RemoveAll { 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"); System.out.println("The Original linked map : " + hash_map); hash_map.clear();// Removing all the elements System.out.println("The New map : " + hash_map); } }
The Original linked map : {1=Pink, 2=Green, 3=Red, 4=White, 5=Blue, 6=Black, 7=Orange} The New map : {}
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions