【发布时间】:2016-12-29 16:40:40
【问题描述】:
我在 Scala 中有一个 Map,其中的值是列表列表。我尝试使用以下代码添加一个值:
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。如果我需要向列表中添加列表,为什么需要 String?我需要将list1 添加到listInMap
【问题讨论】:
标签: scala