java - 100% 准确的 key,value HashMap

标签 java hashmap key-value

根据网页http://www.javamex.com/tutorials/collections/hash_codes_advanced.shtml

hash codes do not uniquely identify an object. They simply narrow down the choice of matching items, but it is expected that in normal use, there is a good chance that several objects will share the same hash code. When looking for a key in a map or set, the fields of the actual key object must therefore be compared to confirm a match."

首先,这是否意味着 has 映射中使用的键也可能指向多个值?我认为是的。

如果是这样的话。如何创建“始终准确”的 HashMap 或类似的键值对象?

我的键需要是字符串,我的值也需要是字符串。我需要大约 4,000 到 10,000 个键值对。

最佳答案

标准 HashMap 将保证唯一键。哈希码不等同于 key 。它只是一种将可能值集快速缩减为具有特定哈希码的对象(在您的情况下为字符串)的方法。

关于java - 100% 准确的 key,value HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11271722/

相关文章:

java - PMD的StringInstantiation规则背后的 "Why"

java - 如何生成具有不同数量空格的字符串或如何在字符串后添加空格

java - 使用接口(interface)实例化和具体类实例化之间的区别? (HashMap、Map & List、ArrayList)

java - Hadoop 中的 HashMap

erlang - Erlang 中的命令?

java - 具有多个字段的 Spring 自定义注释验证

python - 使用预计算针对特定用例优化 Python 算法

java - 装饰一个 HashMap 添加随机性以防止 (DDoS

javascript - 一个对象如何从对象列表中分组并仅收集明确引用的特定值,每个值都通过其键?

java - 如何为 JDBC 连接设置时区区域并避免找不到 SqlException 时区区域?