Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   RUBY   
   C++   




TOMUTABLEMAP() - FUNCTION


The toMutableMap() method is used to copy one Map to the other creating a mutable Map.


Example :



fun main() {

    var x = mutableMapOf(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
    var y = x.toMutableMap()
    println("The Copied Map is "+y)
}


Output :



  The Copied Map is {5=Is a Number, John=Is a Name, Kotlin=Is a Language}

So, in the above code we have created a Map and initialised to the variable x.


var x = toMutableMap(5 to "Is a Number", "John" to "Is a Name", "Kotlin" to "Is a Language")
java_Collections


Then we have taked the Map x and called the toMutableMap() method that creates a new Map that would be the exact copy of x.


Then assign it to y.


	var y = x.toMutableMap()

And if we see the below output,


The Copied Map is {5=Is a Number, John=Is a Name, Kotlin=Is a Language}

The new variable y is an exact copy of x.

java_Collections