How to do that without creating any new collections? Is there something better than this?
val m = scala.collection.mutable.Map[String, Long](\"1\" -> 1, \"2\"
Per the Scala mutable map reference page, you can remove a single element with either -= or remove, like so:
val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4)
m -= "1" // returns m
m.remove("2") // returns Some(2)
The difference is that -= returns the original map object, while remove returns an Option containing the value corresponding to the removed key (if there was one.)
Of course, as other answers indicate, if you want to remove many elements based on a condition, you should look into retain, filter, etc.