Google Collections ImmutableMap迭代顺序

编程入门 行业动态 更新时间:2024-10-14 16:23:34
本文介绍了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. Unfortunately quick look into the sources didn't help me very much.

我的问题是:我可以依赖ImmutableMap的迭代顺序吗?如果我执行 ImmutableMap.copyOf(linkedHashMap),它是否与原始链接哈希映射具有相同的迭代顺序?构建器创建的不可变映射怎么样?一些权威答案的链接会有所帮助,因为谷歌没有找到任何有用的东西。 (不,链接到源不计)。

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

本文发布于:2023-11-30 02:14:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   迭代   Google   Collections   ImmutableMap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!