[mw_shl_code=scala,true]def main(args : Array[String]) : Unit = {
var test : Map[String, String] = Map()
test += ("1" -> "2")
test += ("2" -> "3")
for(i <- 0 until 3){
test += (("s"+i) -> "4")
}
//val ret = test.toList
//ret.foreach(println)
var arr : Array[String] = Array("e", "r", "t")
var key = "first"
for(i <- 0 until arr.length){
test += (key -> arr(i))
}
val ret = test.toList
ret.foreach(println)
}[/mw_shl_code]
打印的结果
(s2,4)
(1,2)
(s1,4)
(first,t)
(2,3)
(s0,4)
问题即,为什么在数组循环里面,Map里面为什么不能添加新的元素,只保留了最后一个 (first,t)
|
|