HashMap1.7 and different points of the 1.8

  1. JDK1.7 using a first interpolation method, and JDK1.8 and after the end of interpolation is used, then why do it? Because
    the longitudinally extending JDK1.7 is carried out with a single linked list, when the first interpolation method is adopted It can improve the insertion efficiency, but also easy to reverse the cycle of death and circular linked list problems. But after JDK1.8 is due to the additional use of red-black tree tail interpolation method can avoid the problem in reverse order and the list appears endless loop.

  2. After the calculated expansion data storage location is not - like:
    1) is carried out at the time of JDK1.7 directly with binary numbers and hash value required expansion & (this is why the expansion of the time why necessarily have to be the number 2 where the power of reason, because the situation only if the n-th power of 2 of the last - only a certain bit binary number is 1, thus reducing the hash collision to the greatest extent) (hash value & length-1).

2) when in the direct use JDK1.8 JDK1.7 law when calculated, i.e. the original position before the expansion of the expansion + = JDK1.8 size value is calculated, rather than the JDK1.7 a method that an exclusive oR. However, this approach is equivalent to the new position is determined only involved in computing Hash values ​​0 or 1 is rapidly calculated directly after expansion of the storage methods.

  1. JDK1.7 used when the data structure is an array of single chain +. However, when and after JDK1.8, using a data structure array + + black tree list (when the list reaches a depth of 8 time, that is the default threshold value, expansion to the list will automatically turn into a red-black tree data structure the time complexity becomes O (logN) improves the efficiency of from 0 (N).
Published 272 original articles · won praise 19 · views 20000 +

Guess you like

Origin blog.csdn.net/hello_cmy/article/details/105124159