def main(args: Array[String]): Unit = {
val aMap = new scala.collection.mutable.HashMap[String, Double]
val a = Array("A", "B", "C", "D")
val b = Array(4, 5, 8, 9)
for(i <- a.indices){
aMap += (a(i) -> b(i))
}
// 从小到大(默认)
val mapSortSmall = aMap.toList.sortBy(_._2)
mapSortSmall.foreach(line => println(line._1 +"\t"+ line._2))
// 从大到小
val mapSortBig = aMap.toList.sortBy(-_._2)
}
scala map排序
最新推荐文章于 2021-04-16 18:02:39 发布