The following Scala code that uses java.util.HashMap
(I need to use Java because it's for a Java interface) works fine:
val row1 = new HashMap[String,String](Map("code" -> "B1", "name" -> "Store1"))
val row2 = new HashMap[String,String](Map("code" -> "B2", "name" -> "Store 2"))
val map1 = Array[Object](row1,row2)
Now, I'm trying to dynamically create map1
:
val values: Seq[Seq[String]] = ....
val mapx = values.map {
row => new HashMap[String,String](Map(row.map( col => "someName" -> col))) <-- error
}
val map1 = Array[Object](mapx)
But I get the following compilation error:
type mismatch; found : Seq[(String, String)] required: (?, ?)
How to fix this?
val row1 = new HashMap[String,String](Map("code" -> "B1", "name" -> "Store1"))
works? – Ramesh MaharjanMap
tojava.util.HashMap
does not seem correct. And post might be a duplicate: stackoverflow.com/questions/3843445/… – user3097405