Copy the contents of an immutable map to a new mutable map

Possible duplicate:
How can I convert immutable.Map to mutable.Map in Scala?

How to create a new mutable map with the contents of an immutable map in Scala?

So far I have tried:

val m:scala.collection.mutable.Map[Int, Double] = scala.collection.mutable.Map[Int, Double](imm.map({case(key, value) => (key -> value) })) 

to no avail.

+6
source share
2 answers
 val im = Map(1->1.0, 2->3.0) val mm = collection.mutable.Map[Int,Double]() ++= im 
+21
source
 val immM = Map(1 -> 2) val mutM = collection.mutable.Map(immM.toSeq: _*) 
+7
source

Source: https://habr.com/ru/post/907127/


All Articles