【发布时间】:2021-11-24 07:39:54
【问题描述】:
Map<String, Integer> map = new HashMap<>();
map.put("Naveen", 100);
System.out.println("Naveen".hashCode());
/* output (-1968696341) so index=(-1968696341&15)=11
but in netbeans 8.2 and jdk 1.8 debugger hashcode = -1968662205
so the index=(-1968662205&15)=3[enter image description here][1]
*/
我的环境问题出在哪里 netbeans 8.2 jdk 1.8
调试器 && 控制台
【问题讨论】:
-
它对我有用。我在调试器中看到与屏幕上打印的相同的哈希码。我认为您可能错误地解释了调试器输出。试试
int hash = "Naveen".hashCode();用调试器看代码,应该会看到正确的值。 -
@markspace 我试过 int hash = "Naveen".hashCode();但我得到了相同的结果
-
@user16320675 字符串的 hashCode 是 specified 可重复。
标签: java collections hashmap