Map和Set一样采用了类继承机制提供可变的和不可变的两种版本的Map。同样可以使用Array、List、Set同样的工厂方法构造和初始化
scala> var m2=Map[Int,String]()
m2: scala.collection.immutable.Map[Int,String] = Map()
scala> m2+=(10->"Ten") #10->"Ten"相当于10.->("Ten"),Scala的任何对象都能调用 -> 方法,并返回包含键值对的二元组
scala> m2
res22: scala.collection.immutable.Map[Int,String] = Map(10 -> Ten)
scala> val m4=scala.collection.mutable.Map(1->"One")
m4: scala.collection.mutable.Map[Int,String] = Map(1 -> One)
scala> m4+=(5->"Five")
res25: m4.type = Map(5 -> Five, 1 -> One)
scala> m4
res26: scala.collection.mutable.Map[Int,String] = Map(5 -> Five, 1 -> One)