根据网页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/