Scala Maps and Option
Map("Ada" -> 36) builds an immutable map from key-value pairs. Instead of returning null for a missing key, get returns an Option: Some(value) if the key exists, or None if it does not.
Scala
object Main {
def main(args: Array[String]): Unit = {
val ages = Map("Ada" -> 36, "Grace" -> 45)
println(ages.get("Ada"))
println(ages.get("Linus"))
println(ages.getOrElse("Linus", 0))
}
}