object Demo { def main(args : Array[String]) { var a : Map[String, Int] = Map(); var b = Map("Hannah" -> 12, "Hadley" -> 1); // add pairs a = a + ("Lin" -> 39, "Yanhua" -> 38) println(a.keys); // keys println(a.values); // values // concatenate var c = a ++ b println(c) println(a("Lin")); // access element // foreach a.foreach(t => println(t._1+" "+t._2)) // contains println(a.contains("Lin")) // remove pair a = a - "Lin" println(a) } }
import scala.collection.mutable.Map object Demo { def main(args : Array[String]) { var a : Map[String, Int] = Map("Lin" -> 39, "Yanhua" -> 38) a("Lin") = 40 println(a); } }