can you store multiple null values in hashmap ?
Yes, we can Store null values in HashMap using only one null key. If we store multiple values using null key, then the latest value on key will be displayed.
import java.util.HashMap;
public class TestHashMap
{
public static void main(String a[])
{
HashMap hm = new HashMap();
hm.put(1, "value1");
hm.put(2, "value2");
hm.put(null, "heera");
hm.put(null, "heera babu");
System.out.println(hm);
}
}
Console Output:
{null=heera babu, 1=value1, 2=value2}