"1", "b" -> "2", "c" -> "3" ) m:-6ren">
gpt4 book ai didi

scala - 在 Scala 中将 Map[String, String] 转换为 Map[String, Int]

转载 作者:行者123 更新时间:2023-12-01 07:13:49 25 4
gpt4 key购买 nike

我有一个 Map,其中键是 String,值是 Int,但表示为 String。

scala> val m = Map( "a" -> "1", "b" -> "2", "c" -> "3" ) 
m: scala.collection.immutable.Map[String,String] = Map(a -> 1, b -> 2, c -> 3)

现在我想把它转换成 Map[String, Int]

最佳答案

scala> m.mapValues(_.toInt)
res0: scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2, c -> 3)

关于scala - 在 Scala 中将 Map[String, String] 转换为 Map[String, Int],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22723965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com