java - 在 hashmap 中允许多个空键有什么好处?

标签 java hashmap

只是为了试验,我在 Hashmap 实例中添加了多个 null 键。它没有提示。这样做有什么好处?

代码是,

Map hmap = new HashMap();
hmap.put("sushil","sushil11" );
hmap.put(null,null);
hmap.put(null,"king");
hmap.put(null,"nagasaki");
hmap.put(null,null);

map 上有多少个键?

最佳答案

我猜你没有添加多个 null 键。您只是多次覆盖了相同的 null 键。

关于java - 在 hashmap 中允许多个空键有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4136313/

相关文章:

java - 使用 HashMap 比较两个字谜时出现编译错误

java - 改变图像颜色

java - UnityPlayerActivity全局初始化

hashmap - 无法将字符串以外的值添加到嵌套 HashMap

java - Java 中的二维 HashMap (以及一般情况下)

typescript - 如何检查 Typescript 中的 HashMap 是否为空

java - 字符串什么时候缓存它的哈希码?是在 String 对象创建期间还是在调用 hashcode 方法后?

java - Java 应用程序退出时刷新

java - Keycloak:未为联合用户保存授予的范围

java - 通过 ActiveMQ 的 InitialContext 设置 MaxThreadPoolSize