val mymap = Map("one" -> 1, "two" -> 2, "three" -> 3) for (mykey <- mymap.keySet.toArray.sorted) { // Do something }
Programming Tips - Scala: sort the keys of a Map
Date: 2012dec16
Language: Scala
Q. Scala: sort the keys of a Map
A. Use keySet to obtain the keys. But its a Set which aren't sorted.
So convert it to an Array or List and sort with "sorted".