HashMap原理
2019-12-11 17:26:17 0 举报
HashMap原理
作者其他创作
大纲/内容
1
+key+value+next+hash
......
Entry0
next
HashCode内存地址
Null
Bucket16
15
Java对象的eqauls方法和hashCode方法是这样规定的:相等(相同)的对象必须具有相等的哈希码(或者散列码)原因:HashMap向其put对象的时候,计算hashCode找到存储Bucket,若存储的对象相同,但是hashCode不同,违背原则
HashMap的Entry结构-单链表,next用于维护各个bucket中Entry的链接顺序
hash
value
before
16
after
LinkedHashMap的Entry结构-双向链表,before/after用于维护所有Entry的插入顺序
Entry1
LinkedList
ArraList
+key = null+value = null+next+hash
key
2
LinkedHashMap
3
Entry2
0
Bucket0
收藏
0 条评论
下一页