java - HashMaps 和 Null 值?

标签 java null hashmap hashcode

如何将空值传入 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/

相关文章:

C++ hash_map find() 与 contains() 性能对比

java - NoClassDefFound错误: org/apache/xml/serialize/OutputFormat

java - 从数据库中的列中的唯一值创建链接列表 android sqlite

java - 在jsp中显示日期

java - Android:AIDL 中的自定义对象

java - 错误 : incomparable types: double and <null>

java - Java 如何从 HashMap 中获取对象

objective-c - 应用程序因空变量而崩溃

sql - 空值 - boolean 表达式

java - ThreadLocal可以作为HashMap中的Key吗?