val ex = Map(("A1", (7.8,9.2))
,("A2", (4.2,44.3))
,("A11", (9.0,54.1)))
Without changing the format of the Map, using
ex.toList.sortBy(x=>x._1.substring(1).toInt)
Если вы хотите получить результат путем изменения с Map[String,(Double,Double)]
на Map[String,Double,Double]
, используя
ex.map{case (a,(b,c))=>(a,b,c)}.toList.sortBy(x=>x._1.substring(1).toInt)
В Scala REPL:
scala> ex.toList.sortBy(x=>x._1.substring(1).toInt)
res97: List[(String, (Double, Double))] = List((A1,(7.8,9.2)), (A2,(4.2,44.3)), (A11,(9.0,54.1)))
scala> ex.map{case (a,(b,c))=>(a,b,c)}.toList.sortBy(x=>x._1.substring(1).toInt)
res96: List[(String, Double, Double)] = List((A1,7.8,9.2), (A2,4.2,44.3), (A11,9.0,54.1))