Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Java Program to remove key value pair from HashMap

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class Demo {
	public static void main(String[] args) {
		HashMap<String,String>map = new HashMap<String,String>();
		map.put("1", "A");
		map.put("2", "B");
		map.put("3", "C");
		map.put("4", "D");
		map.put("5", "E");
		map.put("6", "F");
		map.put("7", "G");
		map.put("8", "H");
		map.put("9", "I");
		System.out.println("HashMap...");
		for (String res: map.keySet()) {
			System.out.println(res);
		}
		map.remove("5");
		System.out.println("Updated HashMap...");
		for (String res: map.keySet()) {
			System.out.println(res);
		}
		map.remove("8");
		System.out.println("Updated HashMap...");
		for (String res: map.keySet()) {
			System.out.println(res);
		}
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.