Scala: Using HashMap with a default value
Wow, I happened to visit this thread exactly one year after I posted my last answer here. 🙂 Scala 2.9.1. mutable.Map comes with a withDefaultValue method. REPL session: scala> import collection.mutable import collection.mutable scala> mutable.Map[Int, String]().withDefaultValue(“”) res18: scala.collection.mutable.Map[Int,String] = Map() scala> res18(3) res19: String = “”