linkedhashmap遍历有序
时间: 2023-08-26 20:13:35 浏览: 128
HashMap遍历
5星 · 资源好评率100%
LinkedHashMap的遍历是有序的,遍历顺序和插入顺序一致。这是因为LinkedHashMap内部使用了双向链表来维护元素的插入顺序。每次插入新的元素时,会将该元素插入到链表尾部,保证了后插入的元素在链表的尾部。在遍历时,从链表的头结点开始遍历,输出的顺序就和插入的顺序一致。这使得LinkedHashMap可以保持插入顺序的特性。所以,当你遍历LinkedHashMap时,会按照元素插入的先后顺序来输出。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [LinkedHashMap是如何实现有序的?](https://blog.csdn.net/zhangjin1120/article/details/121441937)[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^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* *3* [HashMap的无序性与LinkedHashMap的有序性](https://blog.csdn.net/xiangqian_/article/details/103252188)[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^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文