How to convert Scala's scala.List
into Java's java.util.List
?
Not sure why this hasn't been mentioned before but I think the most intuitive way is to invoke the asJava
decorator method of JavaConverters directly on the Scala list:
scala> val scalaList = List(1,2,3)
scalaList: List[Int] = List(1, 2, 3)
scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
scala> scalaList.asJava
res11: java.util.List[Int] = [1, 2, 3]