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 迭代顺序


- 未找到/usr/local/lib 中的库 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01