This object contains methods that convert between Scala and Java collections.
The explicit conversion methods defined here are intended to be used in Java code. For Scala code, it is recommended to use the extension methods defined inscala.jdk.CollectionConverters.
Note: to createJava Streams that operate on Scala collections (sequentially or in parallel), useStreamConverters.
// Java Codeimport scala.jdk.javaapi.CollectionConverters;public class A { public void t(scala.collection.immutable.List<String> l) { java.util.List<String> jl = CollectionConverters.asJava(l); }}The conversions return adapters for the corresponding API, i.e., the collections are wrapped, not converted. Changes to the original collection are reflected in the view, and vice versa.
The following conversions are supported viaasScala andasJava:
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.concurrent.Map <=> java.util.concurrent.ConcurrentMapThe following conversions are supported viaasScala and through specially-named methods to convert to Java collections, as shown:
scala.collection.Iterable <=> java.util.Collection (via asJavaCollection)scala.collection.Iterator <=> java.util.Enumeration (via asJavaEnumeration)scala.collection.mutable.Map <=> java.util.Dictionary (via asJavaDictionary)In addition, the following one-way conversions are provided viaasJava:
scala.collection.Seq => java.util.Listscala.collection.mutable.Seq => java.util.Listscala.collection.Set => java.util.Setscala.collection.Map => java.util.MapThe following one way conversion is provided viaasScala:
java.util.Properties => scala.collection.mutable.MapIn all cases, converting from a source type to a target type and back again will return the original source object.
Converts a Scala mutableconcurrent.Map to a JavaConcurrentMap.
Converts a Scala mutableconcurrent.Map to a JavaConcurrentMap.
The returned JavaConcurrentMap is backed by the provided Scalaconcurrent.Map and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the Scalaconcurrent.Map was previously obtained from an implicit or explicit call ofasScala then the original JavaConcurrentMap will be returned.
The Scalaconcurrent.Map to be converted.
A JavaConcurrentMap view of the argument.
Converts a ScalaMap to a JavaMap.
Converts a ScalaMap to a JavaMap.
The returned JavaMap is backed by the provided ScalaMap and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaMap was previously obtained from an implicit or explicit call ofasScala then the original JavaMap will be returned.
The ScalaMap to be converted.
A JavaMap view of the argument.
Converts a Scala mutableMap to a JavaMap.
Converts a Scala mutableMap to a JavaMap.
The returned JavaMap is backed by the provided ScalaMap and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaMap was previously obtained from an implicit or explicit call ofasScala then the original JavaMap will be returned.
The Scala mutableMap to be converted.
A JavaMap view of the argument.
Converts a ScalaSet to a JavaSet.
Converts a ScalaSet to a JavaSet.
The returned JavaSet is backed by the provided ScalaSet and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaSet was previously obtained from an implicit or explicit call ofasScala then the original JavaSet will be returned.
The ScalaSet to be converted.
A JavaSet view of the argument.
Converts a Scala mutableSet to a JavaSet.
Converts a Scala mutableSet to a JavaSet.
The returned JavaSet is backed by the provided ScalaSet and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaSet was previously obtained from an implicit or explicit call ofasScala then the original JavaSet will be returned.
The Scala mutableSet to be converted.
A JavaSet view of the argument.
Converts a ScalaSeq to a JavaList.
Converts a ScalaSeq to a JavaList.
The returned JavaList is backed by the provided ScalaSeq and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaSeq was previously obtained from an implicit or explicit call ofasScala then the original JavaList will be returned.
The ScalaSeq to be converted.
A JavaList view of the argument.
Converts a Scala mutableSeq to a JavaList.
Converts a Scala mutableSeq to a JavaList.
The returned JavaList is backed by the provided ScalaSeq and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaSeq was previously obtained from an implicit or explicit call ofasScala then the original JavaList will be returned.
The ScalaSeq to be converted.
A JavaList view of the argument.
Converts a Scala mutableBuffer to a Java List.
Converts a Scala mutableBuffer to a Java List.
The returned Java List is backed by the provided ScalaBuffer and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaBuffer was previously obtained from an implicit or explicit call ofasScala then the original JavaList will be returned.
The ScalaBuffer to be converted.
A JavaList view of the argument.
Converts a ScalaIterable to a JavaIterable.
Converts a ScalaIterable to a JavaIterable.
The returned JavaIterable is backed by the provided ScalaIterable and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaIterable was previously obtained from an implicit or explicit call ofasScala then the original JavaIterable will be returned.
The ScalaIterable to be converted.
A JavaIterable view of the argument.
Converts a ScalaIterator to a JavaIterator.
Converts a ScalaIterator to a JavaIterator.
The returned JavaIterator is backed by the provided ScalaIterator and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaIterator was previously obtained from an implicit or explicit call ofasScala then the original JavaIterator will be returned.
The ScalaIterator to be converted.
A JavaIterator view of the argument.
Converts a ScalaIterable to an immutable JavaCollection.
Converts a ScalaIterable to an immutable JavaCollection.
If the ScalaIterable was previously obtained from an implicit or explicit call ofasScala then the original JavaCollection will be returned.
The ScalaIterable to be converted.
A JavaCollection view of the argument.
Converts a Scala mutableMap to a JavaDictionary.
Converts a Scala mutableMap to a JavaDictionary.
The returned JavaDictionary is backed by the provided ScalaDictionary and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaMap was previously obtained from an implicit or explicit call ofasScala then the original JavaDictionary will be returned.
The ScalaMap to be converted.
A JavaDictionary view of the argument.
Converts a ScalaIterator to a JavaEnumeration.
Converts a ScalaIterator to a JavaEnumeration.
The returned JavaEnumeration is backed by the provided ScalaIterator and any side-effects of using it via the Java interface will be visible via the Scala interface and vice versa.
If the ScalaIterator was previously obtained from an implicit or explicit call ofasScala then the original JavaEnumeration will be returned.
The ScalaIterator to be converted.
A JavaEnumeration view of the argument.
Converts a JavaProperties to a Scala mutableMap[String, String].
Converts a JavaProperties to a Scala mutableMap[String, String].
The returned ScalaMap[String, String] is backed by the provided JavaProperties and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
The JavaProperties to be converted.
A Scala mutableMap[String, String] view of the argument.
Converts a JavaDictionary to a Scala mutableMap.
Converts a JavaDictionary to a Scala mutableMap.
The returned ScalaMap is backed by the provided JavaDictionary and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaDictionary was previously obtained from an implicit or explicit call ofasJavaDictionary then the original ScalaMap will be returned.
The JavaDictionary to be converted.
A Scala mutableMap view of the argument.
Converts a JavaConcurrentMap to a Scala mutableConcurrentMap.
Converts a JavaConcurrentMap to a Scala mutableConcurrentMap.
The returned ScalaConcurrentMap is backed by the provided JavaConcurrentMap and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaConcurrentMap was previously obtained from an implicit or explicit call ofasJava then the original ScalaConcurrentMap will be returned.
The JavaConcurrentMap to be converted.
A Scala mutableConcurrentMap view of the argument.
Converts a JavaMap to a Scala mutableMap.
Converts a JavaMap to a Scala mutableMap.
The returned ScalaMap is backed by the provided JavaMap and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaMap was previously obtained from an implicit or explicit call ofasJava then the original ScalaMap will be returned.
If the wrapped map is synchronized (e.g. fromjava.util.Collections.synchronizedMap), it is your responsibility to wrap all non-atomic operations withunderlying.synchronized. This includesget, asjava.util.Map's API does not allow for an atomicget whennull values may be present.
The JavaMap to be converted.
A Scala mutableMap view of the argument.
Converts a JavaSet to a Scala mutableSet.
Converts a JavaSet to a Scala mutableSet.
The returned ScalaSet is backed by the provided JavaSet and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaSet was previously obtained from an implicit or explicit call ofasJava then the original ScalaSet will be returned.
The JavaSet to be converted.
A Scala mutableSet view of the argument.
Converts a JavaList to a Scala mutableBuffer.
Converts a JavaList to a Scala mutableBuffer.
The returned ScalaBuffer is backed by the provided JavaList and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaList was previously obtained from an implicit or explicit call ofasJava then the original ScalaBuffer will be returned.
The JavaList to be converted.
A Scala mutableBuffer view of the argument.
Converts a JavaCollection to a ScalaIterable.
Converts a JavaCollection to a ScalaIterable.
If the JavaCollection was previously obtained from an implicit or explicit call ofasJavaCollection then the original ScalaIterable will be returned.
The JavaCollection to be converted.
A ScalaIterable view of the argument.
Converts a JavaIterable to a ScalaIterable.
Converts a JavaIterable to a ScalaIterable.
The returned ScalaIterable is backed by the provided JavaIterable and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaIterable was previously obtained from an implicit or explicit call ofasJava then the original ScalaIterable will be returned.
The JavaIterable to be converted.
A ScalaIterable view of the argument.
Converts a JavaEnumeration to a ScalaIterator.
Converts a JavaEnumeration to a ScalaIterator.
The returned ScalaIterator is backed by the provided JavaEnumeration and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaEnumeration was previously obtained from an implicit or explicit call ofasJavaEnumeration then the original ScalaIterator will be returned.
The JavaEnumeration to be converted.
A ScalaIterator view of the argument.
Converts a JavaIterator to a ScalaIterator.
Converts a JavaIterator to a ScalaIterator.
The returned ScalaIterator is backed by the provided JavaIterator and any side-effects of using it via the Scala interface will be visible via the Java interface and vice versa.
If the JavaIterator was previously obtained from an implicit or explicit call ofasJava then the original ScalaIterator will be returned.
The JavaIterator to be converted.
A ScalaIterator view of the argument.