I have in Scala a Map where the values are list of lists. I try to add a value with the following code:
var map = Map[String,List[List[String]]]()
val list1 = List ("A111", "B111")
var listInMap = map.getOrElse("abc", List[List[String]]())
listInMap += list1 // this line does not compile
map += ("abc" -> listInMap)
listInMap += list1
type mismatch; found : List[String] required: String
list1
listInMap
listInMap += list1
is equivalent to listInMap = listInMap + list1
.
+
operator is not defined in List
for latest scala library (2.11.8) (marked deprecated in 2.7). So, +
operator just concat the string values of listInMap
and list1
with latest scala library.
For latest scala, you can use, listInMap = listInMap :+ list1
Also, check this: http://stackoverflow.com/a/7794297/1433665 as appending to list in scala has complexity of O(n)