我知道 hashmap 实际上使用哈希码来存储和检索哈希表中的对象,但我怀疑它使用的是哪个哈希码。map 实际上包含键的哈希码和值的哈希码。让我们这样考虑
Map<String,String> student=new HashMap();
student.put("name", "foo");
System.out.println("name".hashCode());
System.out.println("foo".hashCode());
Run Code Online (Sandbox Code Playgroud)
在这里,name(key) 的 hashcode 是 3373707,foo(value) 的 hashcode 是 101574
我怀疑它应该使用哪一个来存储和检索对象