我正在通过
Java的hash方法实现put方法,并且遇到了这个:
// Makes sure the key is not already in the hashtable. Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { V old = e.value; e.value = value; return old; } }
虽然我知道需要一个密钥来检查冲突,但为什么Java存储密钥的哈希值并检查它?