#collections #maps #scala

example to declare immutable Maps as follows:

// Empty hash table whose keys are strings and values are integers:
var A:Map[Char,Int] = Map()

// A map with keys and values.
val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF")
If you want to change selection, open document below and click on "Move attachment"

Scala Maps
rt scala.collection.mutable.Map class explicitly. If you want to use both mutable and immutable Maps in the same, then you can continue to refer to the immutable Map as Map but you can refer to the mutable set as mutable.Map. Following is the <span>example to declare immutable Maps as follows: // Empty hash table whose keys are strings and values are integers: var A:Map[Char,Int] = Map() // A map with keys and values. val colors = Map("red" -> "#FF0000", "azure" -> "#F0FFFF") While defining empty map, the type annotation is necessary as the system needs to assign a concrete type to variable. If we want to add a key-value pair to a Map, we can use the operator