HashMaps and Null values?

Neutron_boy picture Neutron_boy · Feb 26, 2013 · Viewed 193k times · Source

How do you pass in null values into a HashMap?
The following code snippet works with options filled in:

HashMap<String, String> options = new HashMap<String, String>();  
options.put("name", "value");
Person person = sample.searchPerson(options);  
System.out.println(Person.getResult().get(o).get(Id));    

So the issue is what has to be entered into the options and or method to pass in a null value?
I tried the following code without any success:

options.put(null, null);  
Person person = sample.searchPerson(null);    

options.put(" ", " ");  
Person person = sample.searchPerson(null);    

options.put("name", " ");  
Person person = sample.searchPerson(null);  

options.put();  
Person person = sample.searchPerson();    

Answer

kenor picture kenor · Feb 26, 2013

HashMap supports both null keys and values

http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html

... and permits null values and the null key

So your problem is probably not the map itself.