我在斯卡拉有这样的地图。
val someData = Some(Map(genderKey -> gender,agekey -> age))
如何获取输出为:
val key= genderkey
val value= gender
val key2 = agekey (Dynamic variable name)
val value2= age (Dynamic variable name)
答案 0 :(得分:1)
赞
someData.map(_.map {
case (k,v) => s"$k = $v"
}
.mkString(" and \n"))
.foreach(result => println(result))