Convert Scala Set into Java (java.util.Set)?
Since Scala 2.12.0 scala.collection.JavaConversions
is deprecated:
Therefore, this API has been deprecated and JavaConverters should be used instead. JavaConverters provides the same conversions, but through extension methods.
And since Scala 2.8.1 you can use scala.collection.JavaConverters
for this purpose:
import scala.collection.JavaConverters._
val javaSet = new java.util.HashSet[String]()
val scalaSet = javaSet.asScala
val javaSetAgain = scalaSet.asJava
If you were asking about Scala 2.8, Java collections interoperability is supplied by scala.collection.JavaConversions
. In this case, you want JavaConversions.asSet(...) (there's one for each direction, Java -> Scala and Scala -> Java).
For Scala 2.7, each scala.collection.jcl class that wraps a Java collection has an underlying
property which provides the wrapped Java collection instance.