Original address: https://www.cnblogs.com/faunjoe88/p/7992319.html
Main content:
1) put question: If two key through Hash%entry[].length to get the same index, will there be a risk of coverage?
Here HashMap uses a concept of chained data structure. We mentioned above that there is a next property in the entry class that refers to the downward one entry.
For example, the first key value to a comes in, by calculating the hash of its key to get the index=0, remember to do: entry[0] = A. After a while. A key value pair B, by calculating its index is also equal to 0, now what?
HashMap will do this:B.next = A, entry[0] = B, if it comes in again C,index is equal to 0, then c.next = B, entry[0] = C;
In this way, we found that Index=0 's place actually accesses the A,b,c three key-value pairs, which are linked by the next property.
So don't worry about it. This means that the last inserted element is stored in the array. so far, the general realization of HASHMAP, we should have been clear.
Of course HashMap also contains some optimization aspects of the implementation, here also say. For example: the length of the entry[] is certain, with the data inside the map getting longer,
So the chain of the same index will be very long, will it affect performance? HashMap inside a factor, as the map size becomes larger, entry[] will be extended with a certain length of rules.
Turn: HashMap Implementation Principle Analysis (Interview question: Two hashcode the same object how to deposit HashMap)