Internally, Hashmaps
use a hashfunction
to find the bin
to which a queried key
belongs. Each of these bins
is itself a LinkedList
.
I don't understand how access time can be constant if these LinkedLists
could get very long, and LinkedLists
don't have constant access time, but linear access time instead.
How does the Java Collections
Library manage to guarantee constant access time even if bins got too large for some reason? What is going on internally? What does Java do internally to minimize the negative effects of this?