The map.clear()
function in Scala is used to remove all elements (key-value pairs) in the map.
The illustration below shows the visual representation of the map.clear()
function.
The following module is required in order to use the function
map.clear()
.
scala.collection.mutable.Map
map_name.clear()
map_name
is the name of the map.
The map.clear()
function does not require any parameters.
Scala’s map.clear()
function is used to erase all of the map’s elements (key-value pairs).
The code below shows how to use the map.clear()
function in Scala.
import scala.collection.mutable.Mapobject Main extends App {//creating mapval map = scala.collection.mutable.Map(1 -> "Tom",2 -> "Alsvin",3 -> "Eddie")//map containg key value pairs before clearprintln("The map elements before clear: " + map);//map after clearmap.clear();println("The map elements after clear: " + map);}