hashmap的简单认识
1.hashmap实现了map接口,是线程不安全的,插入的数据key值不能重复,key和value可以为null。
2.hashmap底层是一个Entry数组+链表。
3.插入一个值,根据key值的hashcode来进行hash运算,得到数组的下标,确定插入位置,如果插入位置已经有了元素,作为链表头部插入。
4.下标值的计算是key的hashcode,h& (length-1)运算等价于对length取模,也就是h%length,但是&比%具有更高的效率。
5.经过这样的计算下标值可以使元素在数组中均匀分布。
6.hashmap底层数组的初始长度是16,负载因子0.75。当数组长度超过16*0.75=12时,数组会扩容成16*2=32。此时要重新计算每个元素在数组中的位置。
7.hashmap中数组长度总是2的n次方。
- Post Title: hashmap的简单认识
- Post Author: HeRui
- Post Link: https://HR2812.cn/2019/03/03/hashmap-demo/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

