3

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(); 
piyush aggarwal
  • 67
  • 1
  • 1
  • 6

3 Answers3

10

Since JavaConversions is deprecated, You can use JavaConverters for this:

List<String> listA = scala.collection.JavaConverters.seqAsJavaList(someScalaFunc())
chengpohi
  • 14,064
  • 1
  • 24
  • 42
2

You can use a Java to Scala implicit converter by importing the following:

import scala.collection.JavaConversions._
Sohum Sachdev
  • 1,397
  • 1
  • 11
  • 23
0
import scala.collection.JavaConverters._

val scalaList = List("A", "B", "c")

scalaList.asJava
Sergey
  • 2,880
  • 3
  • 19
  • 29
Learner
  • 1,170
  • 11
  • 21