Skip to content

Instantly share code, notes, and snippets.

@leifwickland
Last active September 9, 2015 16:49
Show Gist options
  • Save leifwickland/f1338e50704208d75a26 to your computer and use it in GitHub Desktop.
Save leifwickland/f1338e50704208d75a26 to your computer and use it in GitHub Desktop.
j.u.c.ConcurrentMap asScala
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
import scala.collection.JavaConverters._
val m: ConcurrentMap[String, String] = new ConcurrentHashMap[String, String]
m.put("1", "one")
m.put("2", "two")
val cm: scala.collection.concurrent.Map[String, String] = m.asScala
cm += ("3" -> "three")
cm.foreach(println)
~$ scala /tmp/juc.scala
(1,one)
(2,two)
(3,three)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment