A collection of decorators that allow to convert between
Scala and Java collections using asScala and asJava methods.
A collection of decorators that allow to convert between
Scala and Java collections using asScala and asJava methods.
The following conversions are supported via asJava, asScala
scala.collection.Iterable <=> java.lang.Iterablescala.collection.Iterator <=> java.util.Iteratorscala.collection.mutable.Buffer <=> java.util.Listscala.collection.mutable.Set <=> java.util.Setscala.collection.mutable.Map <=> java.util.Mapscala.collection.mutable.concurrent.Map <=> java.util.concurrent.ConcurrentMapIn all cases, converting from a source type to a target type and back again will return the original source object, e.g.
import scala.collection.JavaConverters._ val sl = new scala.collection.mutable.ListBuffer[Int] val jl : java.util.List[Int] = sl.asJava val sl2 : scala.collection.mutable.Buffer[Int] = jl.asScala assert(sl eq sl2)
The following conversions also are supported, but the
direction Scala to Java is done my a more specifically named method:
asJavaCollection, asJavaEnumeration, asJavaDictionary.
scala.collection.Iterable <=> java.util.Collectionscala.collection.Iterator <=> java.util.Enumerationscala.collection.mutable.Map <=> java.util.Dictionary In addition, the following one way conversions are provided via asJava:
scala.collection.Seq => java.util.Listscala.collection.mutable.Seq => java.util.Listscala.collection.Set => java.util.Setscala.collection.Map => java.util.Map
2.8.1