I cannot say why the two answers rely on HashMap.tranfer for some example, when this method is generally absent in java-8. So I provided my little input, considering java-8.
The entries in the HashMap indeed reissued, but not in the sense you might think of. The repeated hash basically redistributes the ones already provided (by you) from Key#hashcode ; There is a way to do this:
static final int hash(Object key) { int h; return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); }
So, basically, when you calculate your hash code, the HashMap will basically say โI don't trust you enoughโ, and it will re-hash your hash code and it might be better to allocate a bit (this is actually XOR first 16 bits and the last 16 bits).
On the other hand, when the HashMap changes size, it actually means that the number of silos / buckets doubles in size; and because bins always have two strengths - this means that the record from the current bunker will be: potential stay in the same bucket OR moving to a bucket that is offset with the current number of bins. You can find some details on how this is done in this matter .
So, once re-size occurs, there is no additional re-hashing; in fact, one more bit is taken into account, and thus the record can move or stay where it is. And Gray's answer is correct in this sense that each Entry has a hash field that is evaluated only once - the first time you put this Entry .
Eugene
source share