HashMap put(K, V) process

2022-03-24  本文已影响0人  君子兰琚琚

put(K, V) process of the jdk 1.8 HashMap

  1. calculate key hash value
  2. hash table is null or empty ?
    init hash table by invoke resize() that if hash table is null or empty
  3. calculate the index of key in the hash table
    1. hash conflict
      1. is want to replace value ?
        replace new value
      2. is red-black tree ?
        add new node
      3. append element into list
        1. list size is >= 7 ?
          transformed the red-black tree when the list size is >= 7
    2. not conflict
      put the element into the hash table
上一篇下一篇

猜你喜欢

热点阅读