1

I am initializing a map with a bunch of values. The order of the values is important, and when I do myMap.values(), I'd like them to all come out in the order they went in. What data structure should I be using for that?

Map<String, String> myMap = new SomeKindOfMap<String, String>();
myMap.put(key1, value1)
myMap.put(key2, value2)
//etc
Steve
  • 4,457
  • 12
  • 48
  • 89

1 Answers1

3

You're looking for a LinkedHashMap. Pro tip: If you go to the JavaDoc for an interface like Map, there's a "All Known Implementing Classes" section where you can see a list of all implementations in the JDK, and see if any meet your needs...

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875