HashMap put(K, V) process

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

你可能感兴趣的:(HashMap put(K, V) process)