我有一个这样的字符串:
myString = "Name:varchar nullable ,Age:varchar nullable,BirthTimestamp:varchar nullable,Time:varchar nullable,ZipCode:varchar nullable,Address:varchar nullable"
我正在尝试像这样解析这个字符串 - >
val tmp = myString.split(",").map(x=>x.split(":")).map(x=>
x(0)->x(1).split(" ")).toMap
tmp.foreach(x=>println(x._1+" "+x._2.foreach(y=>print(y))))
打印为
varcharnullableName ()
varcharnullableAddress () --> Why Address is printed here instead of Map?
varcharnullableBirthTimestamp ()
varcharnullableAge ()
varcharnullableZipCode ()
varcharnullableTime ()
如何保留这些元素的顺序,类似于输入字符串?
此致
答案 0 :(得分:1)
因为Map
是无序的,只需删除.toMap
就可以了:
val tmp = myString.split(",").map(x=>x.split(":")).map(x=>
x(0)->x(1).split(" "))