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


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