Scala Map 实现按插入顺序保留条目? [英] Scala Map implementation keeping entries in insertion order?

查看:65
本文介绍了Scala Map 实现按插入顺序保留条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中,我为此使用了 LinkedHashMap.Java 的 LinkedHashMap 的文档非常清楚,它具有可预测的迭代顺序",而我在 Scala 中也需要相同的内容.

In Java, I use LinkedHashMap for this purpose. The documentation of Java's LinkedHashMap is very clear that it has "predictable iteration order" and I need the same in Scala.

Scala 有 ListMapLinkedHashMap,但是关于它们具体做什么的文档很差.

Scala has ListMap and LinkedHashMap, but the documentation on what they do exactly is poor.

问题:Scala 的 LinkedHashMapListMap 是用于此目的的实现吗?如果没有,除了直接使用 Java 的 LinkedHashMap 之外,还有哪些其他选择?

Question: Is Scala's LinkedHashMap or ListMap the implementation to use for this purpose? If not, what other options are available besides using the Java's LinkedHashMap directly?

推荐答案

来自 LinkedHashMap Scaladoc 页面:

From the LinkedHashMap Scaladoc page:

  • "此类使用哈希表实现可变映射.迭代器和此类的所有遍历方法都按元素访问的顺序访问元素插入."

这篇关于Scala Map 实现按插入顺序保留条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆