Convert from java.util.Vector to scala Seq

I see that there are ways to convert from a Java list to a Scala sequence (using the asScala method), but I could not find the converters for java.util.Vector .

Is there a similar way for this conversion too?

+6
source share
3 answers

JavaConverters bit more idiomatic than JavaConversions .

 import collection.JavaConverters._ val v = new java.util.Vector[Int] val s: Seq[Int] = v.asScala 
+12
source

Import JavaConversions :

 import collection.JavaConversions._ val v = new java.util.Vector[Int]() val s = v.toSeq // s is of type Seq[Int] 
+2
source

Note that starting with Scala 2.13 , the scala.jdk.CollectionConverters package provides asScala through the java.util.List pimp and replaces the scala.collection.JavaConverters/JavaConversions :

 import scala.jdk.CollectionConverters._ // val javaVector = new java.util.Vector(java.util.Arrays.asList(1, 2, 3)) javaVector.asScala.toSeq // Seq[Int] = List(1, 2, 3) 
0
source

All Articles