ordered map implementation

大兔子大兔子 提交于 2019-12-30 22:56:53

问题


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());
}

Will always print

4, d
10, y
2, b

I'm using Java 5.0.

Thanks, Don


回答1:


That's LinkedHashMap



来源:https://stackoverflow.com/questions/3288860/ordered-map-implementation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!