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
That's LinkedHashMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With