java - Hashmap 的空索引里面有什么?

标签 java hashmap

我有一个大小为 101 个键的 HashMap ,但我确信其中大约 6 个键内部没有数据,并且可能还有更多没有数据。空索引里面到底是什么?是否为空?或者是否有一个 Hash(index).isEmpty() 方法可以用来查看它是否为空?

我意识到 hashmap 中有一个 isEmpty 方法,但我认为它只检查整个映射是否为空,而不仅仅是单个索引。

最佳答案

I realize there is a isEmpty method inside hashmap, but I thought that only checked if the entire map was empty not just a single index.

我认为您正在寻找的是 containsKey(Object) method 。根据文档:

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

Parameters:

key - key whose presence in this map is to be tested

Returns:

true if this map contains a mapping for the specified key

关于java - Hashmap 的空索引里面有什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3308782/

相关文章:

java - 从其他类访问 HashMap 时出现问题

java - 解析JSON并将其放入HashMap中

java - 修复强制转换 List<ArrayObject> 中的警告

java - 从 flow.xml 打印日志

java - 基于Java的Spring配置中搜索资源时如何使用通配符?

java - 通过 API 更新枚举

java - Java MySQL 连接错误

java - Java8 中的 HashMap 条目对流?

java - 如何查找多种语言的国家/地区代码

hashmap - 为什么 LinkedList 作为 HashMap 的存储桶实现而不是另一个 Hashmap?