4 ms·
import scala.collection.JavaConverters._ Scala doesn't provide a built in for your specific case but import scala.collection.breakOut and you can convert mut
by zohebv 15y ago
import scala.collection.JavaConverters._
Scala doesn't provide a built in for your specific case but
import scala.collection.breakOut
and you can convert mutable Java hash map to immutable scala map
b = a.asScala.map(p => p)(breakOut)
where b : scala.collection.immutable.HashMap[java.lang.String,Int]
and a : java.util.HashMap[String,Int]
Not too bad at all. Moreover, why would you want to convert a Java map to Scala if you specifically used the Java map to improve performance? How is this any worse than coding in Java itself?