HashMap implementation issue

HashMap contains a hash table, which is an array that contains values

since I realized that the hash table has an initial size, but may increase after many put () calls (depending on load factor)

In any case, I wonder how you can find the value after changing the size of the hash table, because I know that to calculate code with a certain key, you can use the size of the table

e.g. key * prime% size

so how does it work?

+3
source share
3 answers

Visage : , , , , .

, Java 1.4, , , . , - , . Java 1.4 HashMap ! , - - , .

Java, 54 54b.

+3

, . , .

+2

If you look at the method code addEntry(..), you will see:

if (size++ >= threshold)
   resize(2 * table.length);

When resizing, a method is called transfer(..)that:

Passes all records from the current table to newTable.

+2
source

Source: https://habr.com/ru/post/1756700/


All Articles