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

Null value as key in Java HashMap

import java.util.HashMap;
import java.util.Map;
public class Demo {
	public static final void main(String[] args) {
		Map<String,String>map = new HashMap<>();
		map.put("Football", "A");
		map.put("Squash", "B");
		map.put("Cricket", "C");
		map.put("Hockey", "D");
		map.put("Rugby", "E");
		map.put("Golf", "F");
		map.put("Archery", "G");
		System.out.println("Size of HashMap = " + map.size());
		map.put(null, "H");
		System.out.println("Updated Size of HashMap = " + map.size());
		System.out.println("For null = " + map.get(null));
	}
}

Advertisements
Loading...

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