--------------------------------In the begining of this paper,we give a picture to overview the hashmap----------------------------------------
the key and value in hashmap can be null.
hashmap
from the picture above,we can know the data structure of hashmap is:
一个数组+N个链表,数组每一项对应一个链表。
即:ArrayList<Entry<Key,value>>[ ]
HashMap存储的实现原理:当我们往HashMap中put元素的时候,先根据key的hashCode重新计算hash值(hashCode & (table.length -1)),根据hash值得到这个元素在数组中的位置(即下标),如果数组该位置上已经存放有其他元素了,那么在这个位置上的元素将以链表的形式存放,新加入的放在链头,最先加入的放在链尾。如果数组该位置上没有元素,就直接将该元素放到此数组中的该位置上。
just like this:
data structure
在hashmap 中查询的实现
just like this:
计算key的hashcode
we give a flowchat for the method put(key,value) of hashmap
flowchat