I am studying how HashMap works inside and can not understand this method:
void addEntry(int hash, K key, V value, int bucketIndex) { Entry<K,V> e = table[bucketIndex]; table[bucketIndex] = new Entry<K,V>(hash, key, value, e); if (size++ >= threshold) resize(2 * table.length);
Why object e gets the address (or what happens here?) of table[bucketIndex] and then this table[bucketIndex] get the new Entry(hash, key, value, e)? What is the reason, why didn't just use what is below?
Entry<K,V> e = new Entry<K,V>(hash, key, value)
table[bucketIndex] = e;