如何将空值传递到 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();
原文由 Neutron_boy 发布,翻译遵循 CC BY-SA 4.0 许可协议
HashMap 同时支持
null
键和值http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html
所以你的问题可能不是地图本身。