Scala地图选项

时间:2018-07-11 11:51:49

标签: json scala scala-collections jackson-databind

我在斯卡拉有这样的地图。

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)

1 个答案:

答案 0 :(得分:1)

someData.map(_.map { 
    case (k,v) => s"$k = $v" 
}
.mkString(" and \n"))
.foreach(result => println(result))