一、List
var x = List(1,2,3,4)
二、Set
var x = Set(1,2,3,4)
三、Map
(1) 创建Map
var x = Map("one" -> "1","two" -> "2")
var x:Map[String,String] = Map()
(2) 添加key-value
x += ("three" -> "three")
(3) 合并
使用 ++
运算符 或 Map.++()
方法来连接两个Map
var colors = color1 ++ color2
var colors = color1.++(color2)
(4) 遍历
val sites = Map("one"->"one","two"->"two","three"->"three")
sites.keys.foreach{
i =>
println("key="+i+",value="+sites(i))
}