我正在尝试转换List("a,1" , "b,2" , "c,3" , "a,2" , "b,4")
为scala.collection.immutable.HashMap[String, java.util.List[String]]
带值的类型:
a -> 1,2
b -> 2,4
c -> 3
所以每个键都包含一个其值的列表。
到目前为止,这是我的代码:
object ConvertList extends Application {
var details = new scala.collection.immutable.HashMap[String, java.util.List[String]]
val strList = List("a,1" , "b,2" , "c,3" , "a,2" , "b,4")
//Get all values
val getValue : Function1[String, String] = { a => a.split(",")(1) }
val allValues : List[String] = strList map getValue
//get unique values
val uniqueValues = allValues.toSet[String]
//Somehow map each unique value to a value in the original List....
println(uniqueValues)
println(strList.flatten)
//userDetails += "1" -> List("a","b",
}
如何执行此转换?