Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ordered map implementation

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

like image 487
Dónal Avatar asked Jul 20 '10 10:07

Dónal


1 Answers

That's LinkedHashMap

like image 174
unbeli Avatar answered Sep 29 '22 23:09

unbeli