Google Collections ImmutableMap iteration order(Google Collections ImmutableMap 迭代顺序)
问题描述
我需要 Google Collection ImmutableMap
和 LinkedHashMap
的组合 —具有定义迭代顺序的不可变映射.似乎 ImmutableMap 本身实际上已经定义了迭代顺序,至少 它的文档说:
I need combination of Google Collection ImmutableMap
and LinkedHashMap
— immutable map with defined iteration order. It seems that ImmutableMap itself actually has defined iteration order, at least its documentation says:
一个不可变的、基于散列的 Map,具有可靠的用户指定的迭代顺序.
An immutable, hash-based Map with reliable user-specified iteration order.
但是没有更多细节.快速测试表明这可能是真的,但我想确定一下.
However there are no more details. Quick test shows that this might be true, but I want to make sure.
我的问题是:我可以依赖 ImmutableMap 的迭代顺序吗?如果我执行 ImmutableMap.copyOf(linkedHashMap)
,它的迭代顺序是否与原始链接哈希映射相同?由builder创建的不可变地图呢?一些权威答案的链接会有所帮助,因为谷歌没有发现任何有用的东西.(不,源链接不算在内).
My question is: can I rely on iteration order of ImmutableMap? If I do ImmutableMap.copyOf(linkedHashMap)
, will it have same iteration order as original linked hash map? What about immutable maps created by builder? Some link to authoritative answer would help, since Google didn't find anything useful. (And no, links to the sources don't count).
推荐答案
更准确地说,ImmutableMap 工厂方法和构建器返回的实例遵循构建映射时提供的输入的迭代顺序.然而,一个 ImmutableSortedMap,它是 ImmutableMap 的一个子类.对键进行排序.
To be more precise, the ImmutableMap factory methods and builder return instances that follow the iteration order of the inputs provided when the map in constructed. However, an ImmutableSortedMap, which is a subclass of ImmutableMap. sorts the keys.
这篇关于Google Collections ImmutableMap 迭代顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Google Collections ImmutableMap 迭代顺序
基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01