HashMap principle and source code parsing


Zhou Yu teacher good


1, hashMap mechanism

     1.1, jdk1.7

             Array (entity) + list.

             1.1.1 The key hashCode calculated value, and then perform a high operation hashCode, and finally the array length (initial capacity) -1 ANDed to obtain the storage location of the entity.

             1.1.2, key calculated from the plurality of objects stored in the position as possible, that hash collisions, this time in the same location to increase the list, the list is used in the first expansion interpolation, so that a high efficiency of insertion.

             1.1.3, when the key is null when the specified location, and laid the first index position of the entity.

                        When the same key value will replace the value of the time, while the return oldValue.

                        When the initial capacity, N is the power of 2, mainly in the late time hashCode & calculation, a hash of enhanced. For example, if it is minus 0001 0000 0000 1111, so for bit operation depends on the value of the bit after the operation hashCode. If the specified initial capacity is 10, then the initial capacity is closest to the N-th power of 2, 10, 16


      1.2, jdk1.8

            + + Array list red-black tree



Guess you like

Origin www.cnblogs.com/dsxStudyNote/p/11804485.html