如何将空值传入 HashMap?
以下代码片段适用于填写的选项:
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));
那么问题是必须在选项和/或方法中输入什么来传递空值?
我尝试了以下代码但没有成功:
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();
最佳答案
HashMap 支持 null
键和值
http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html
... and permits null values and the null key
所以你的问题可能不是 map 本身。
关于java - HashMaps 和 Null 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15091148/