java中LinkedHashMap的使用与底层原理
时间: 2023-08-17 17:08:29 浏览: 185
回答: LinkedHashMap是HashMap的子类,直接继承了HashMap类,并且节点元素为Entry<K,V>,继承了HashMap.Node<K,V>。LinkedHashMap在使用上与HashMap基本相同,使用的仍然是HashMap的put方法来插入节点对象。不同的是,LinkedHashMap重写了afterNodeInsertion和afterNodeAccess方法。LinkedHashMap的底层原理是通过维护一个双向链表来保持插入顺序或者访问顺序。每次插入新的节点时,会将新节点插入到链表的尾部;每次访问一个节点时,会将该节点移动到链表的尾部。这样可以保证在遍历LinkedHashMap时按照插入顺序或者访问顺序进行遍历。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* [LinkedHashMap原理和底层实现](https://blog.csdn.net/qq_45839663/article/details/127691432)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Java集合------LinkedHashMap底层原理](https://blog.csdn.net/xiaoyao2246/article/details/88836769)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文