Reputation: 87
I am working in Java. I am calling a scala function which returns a Seq[String]. To convert it to java's List, I tried using scala.collection.JavaConverters's asJava. But this does not seem to work.
Answers on similar questions have suggested either using JavaConversions or WrapAsJava, both of which are deprecated.
Similar Question - Converting Scala seq<string> to Java List<string>
//someScalaFunc returns a Seq[String]
List<String> listA = someScalaFunc();
Upvotes: 5
Views: 15029
Reputation: 1190
import scala.collection.JavaConverters._
val scalaList = List("A", "B", "c")
scalaList.asJava
Upvotes: 0
Reputation: 14227
Since JavaConversions
is deprecated, You can use JavaConverters
for this:
List<String> listA = scala.collection.JavaConverters.seqAsJavaList(someScalaFunc())
Upvotes: 12
Reputation: 1397
You can use a Java to Scala implicit converter by importing the following:
import scala.collection.JavaConversions._
Upvotes: 2