Scala Map implementation keeping entries in insertion order?

Solution 1:

From the LinkedHashMap Scaladoc page:

  • "This class implements mutable maps using a hashtable. The iterator and all traversal methods of this class visit elements in the order they were inserted."

Solution 2:

The difference between the two is that LinkedHashMap is mutable while ListMap is immutable. Otherwise they both are MapLike and also preserve insertion order.