How to convert a scala.List to a java.util.List?

Alex Baranosky picture Alex Baranosky · Mar 12, 2010 · Viewed 76.9k times · Source

How to convert Scala's scala.List into Java's java.util.List?

Answer

dimitrisli picture dimitrisli · Dec 29, 2013

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]