93

LinkedHashMap 底层分析 | crossoverJie's Blog

 6 years ago
source link: https://crossoverjie.top/2018/02/06/LinkedHashMap/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
众所周知 HashMap 是一个无序的 Map,因为每次根据 key 的 hashcode 映射到 Entry 数组上,所以遍历出来的顺序并不是写入的顺序。因此 JDK 推出一个基于 HashMap 但具有顺序的 LinkedHashMap 来解决有排序需求的场景。它的底层是继承于 HashMap 实现的,由一个双向链表所构成。LinkedHashMap 的排序方式有两种:根据写入顺序

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK