As always, you should ask if you really need a changeable map.
Immutable cards are trivial to build:
val map = Map( "mykey" -> "myval", "myotherkey" -> "otherval" )
Volatile cards are no different at first build:
val map = collection.mutable.Map( "mykey" -> "myval", "myotherkey" -> "otherval" ) map += "nextkey" -> "nextval"
In both cases, the output will be used to determine the correct type parameters for the map instance.
You can also hold an immutable map in var , then the variable will be updated with a new immutable map instance every time you perform an "update"
var map = Map( "mykey" -> "myval", "myotherkey" -> "otherval" ) map += "nextkey" -> "nextval"
If you do not have initial values, you can use Map.empty:
val map : Map[String, String] = Map.empty
Kevin Wright Oct 22 '10 at 9:34 2010-10-22 09:34
source share