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 是否维护键的顺序?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
