Scala Map remove() method with example
The remove() method is utilized to remove a key from the map and return its value only.
Method Definition: def remove(key: A): Option[B]
Return Type: It returns the value of the key present in the above method as argument.
We use mutable map here, as remove method is a member of mutable map.
prog.scala:16: error: value remove is not a member of scala.collection.immutable.Map[String, Int]
val result = m1.remove(“for”)
one error found
So, if we use immutable map then there is a compile time error.