I have been looking around, but most of them point to a java TreeMap. The only issue with that is I do not want to convert any Scala into java and back. If there really is no way, then I am ok with that, but I would like to hear it from some professionals just to be 100% sure and to have this question on here for others in the future to stumble upon when they have a similar issue. Thanks in advance.
EDIT:
Type: scala.collection.mutable.HashMap[String, String]
In general, a Scala HashMap
does not guarantee the original order.
However, there is the LinkedHashMap
, which states: "The iterator and all traversal methods of this class visit elements in the order they were inserted."
What is the exact type you are dealing with? If you can decide which implementation to use, then you can choose one that maintains order. If you are just given something of type HashMap
, then you're out of luck.
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