I'm new to Scala. I've been trying to convert a java LinkedHashMap to an equivalent collection(LinkedHashMap?) in Scala in order to preserve the insertion order.
Tried following things as suggested in other threads, but nothing seems to work!
scalaAsMap() - is messing up the order
TreeMap() - sort on keys, values, etc. is not something I'm looking for
Explicit conversion is not working.
val f = new java.util.LinkedHashMap[String, java.util.Map[String, String]]
var g: scala.collection.mutable.LinkedHashMap[String, java.util.Map[String, String]] = f
Hmm, how about:
val javaMap = new java.util.LinkedHashMap[String, String]()
val scalaMap = javaMap.asScala
The type of scalaMap is Map[String, String] but under the hood it behaves just like 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