有序映射实现 [英] ordered map implementation

查看:259
本文介绍了有序映射实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个Map实现,按照键值对的添加顺序对它们进行迭代。例如

I'm looking for a Map implementation that iterates over the key-value pairs in the order in which they were added. For example

Map orderedMap = // instantiation omitted for obvious reasons :)
orderMap.put(4, "d");
orderMap.put(10, "y");
orderMap.put(2, "b");

for (Map.Entry entry : orderedMap.entrySet()) {
  System.out.println(entry.getKey() + ", " + entry.getValue());
}

将总是打印

4, d
10, y
2, b

我在使用Java 5.0。

I'm using Java 5.0.

感谢,
Don

Thanks, Don

推荐答案

这是 LinkedHashMap

这篇关于有序映射实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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