Does Java#39;s LinkedHashMap maintain the order of keys?(Java 的 LinkedHashMap 是否维护键的顺序?)
问题描述
调用LinkedHashMap.keySet()时,返回Set的顺序会和key的添加顺序一致吗?
是的.
参见:LinkedHashMap:p><块引用>
这个链表定义了迭代排序,通常是顺序其中钥匙被插入地图(插入顺序).
并来自 HashMap#keySet 文档:
<块引用>集合 [returned] 由地图支持,所以地图的变化反映在集合,反之亦然.
When LinkedHashMap.keySet() is called, will the order of the Set returned be the same as the order the keys were added in?
Yes.
See: LinkedHashMap:
This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).
and from the HashMap#keySet documentation:
The set [returned] is backed by the map, so changes to the map are reflected in the set, and vice-versa.
这篇关于Java 的 LinkedHashMap 是否维护键的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 的 LinkedHashMap 是否维护键的顺序?


基础教程推荐
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01