Map
val romanNumerals = Map("I" -> 1, "V" -> 5, "X" -> 10)
The syntax key -> value is just another way to write the pair (key, value).
-
Mapis the subclass ofIterable.romanNumerals.map((x, y) => (y, x)) -
Mapis function.romanNumerals("I") // 1However, it will throw an error if the key is not found. The better way to query is:
romanNumerals.get("I") // Some(1) romanNumerals.get("aaa") // NoneSomeandNoneare the subclass ofOption.
Updating a Map
m + (k -> v)m ++ kvs