CollectionConverters

scala.jdk.CollectionConverters

This object provides extension methods that convert between Scala and Java collections.

When writing Java code, use the explicit conversion methods defined in javaapi.CollectionConverters instead.

Note: to create Java Streams that operate on Scala collections (sequentially or in parallel), use StreamConverters.

import scala.jdk.CollectionConverters._
val s: java.util.Set[String] = Set("one", "two").asJava

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:

scala> import scala.jdk.CollectionConverters._

scala> val s = collection.mutable.Set("one")
s: scala.collection.mutable.Set[String] = HashSet(one)

scala> val js = s.asJava
js: java.util.Set[String] = [one]

scala> js.add("two")

scala> s
res2: scala.collection.mutable.Set[String] = HashSet(two, one)

The following conversions are supported via asScala and asJava:

scala.collection.Iterable       <=> java.lang.Iterable
scala.collection.Iterator       <=> java.util.Iterator
scala.collection.mutable.Buffer <=> java.util.List
scala.collection.mutable.Set    <=> java.util.Set
scala.collection.mutable.Map    <=> java.util.Map
scala.collection.concurrent.Map <=> java.util.concurrent.ConcurrentMap

The following conversions are supported via asScala and through specially-named extension 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 via asJava:

scala.collection.Seq         => java.util.List
scala.collection.mutable.Seq => java.util.List
scala.collection.Set         => java.util.Set
scala.collection.Map         => java.util.Map

The following one way conversion is provided via asScala:

java.util.Properties => scala.collection.mutable.Map

In all cases, converting from a source type to a target type and back again will return the original source object. For example:

import scala.jdk.CollectionConverters._

val source = new scala.collection.mutable.ListBuffer[Int]
val target: java.util.List[Int] = source.asJava
val other: scala.collection.mutable.Buffer[Int] = target.asScala
assert(source eq other)

Attributes

Source
CollectionConverters.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Inherited classlikes

implicit class BufferHasAsJava[A](b: Buffer[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class CollectionHasAsScala[A](c: Collection[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class ConcurrentMapHasAsJava[K, V](m: Map[K, V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class ConcurrentMapHasAsScala[K, V](m: ConcurrentMap[K, V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class DictionaryHasAsScala[K, V](d: Dictionary[K, V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class EnumerationHasAsScala[A](e: Enumeration[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class IterableHasAsJava[A](i: Iterable[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class IterableHasAsScala[A](i: Iterable[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class IteratorHasAsJava[A](i: Iterator[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class IteratorHasAsScala[A](i: Iterator[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class ListHasAsScala[A](l: List[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class MapHasAsJava[K, V](m: Map[K, V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class MapHasAsScala[K, V](m: Map[K, V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class MutableMapHasAsJava[K, V](m: Map[K, V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class MutableSeqHasAsJava[A](s: Seq[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class MutableSetHasAsJava[A](s: Set[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class PropertiesHasAsScala(i: Properties)

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class SeqHasAsJava[A](s: Seq[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class SetHasAsJava[A](s: Set[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
class Object
trait Matchable
class Any
implicit class SetHasAsScala[A](s: Set[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
class Object
trait Matchable
class Any

Implicits

Inherited implicits

implicit def BufferHasAsJava[A](b: Buffer[A]): BufferHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def ConcurrentMapHasAsJava[K, V](m: Map[K, V]): ConcurrentMapHasAsJava[K, V]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def ConcurrentMapHasAsScala[K, V](m: ConcurrentMap[K, V]): ConcurrentMapHasAsScala[K, V]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def DictionaryHasAsScala[K, V](d: Dictionary[K, V]): DictionaryHasAsScala[K, V]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def IterableHasAsJava[A](i: Iterable[A]): IterableHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def IterableHasAsScala[A](i: Iterable[A]): IterableHasAsScala[A]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def IteratorHasAsJava[A](i: Iterator[A]): IteratorHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def IteratorHasAsScala[A](i: Iterator[A]): IteratorHasAsScala[A]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def ListHasAsScala[A](l: List[A]): ListHasAsScala[A]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def MapHasAsJava[K, V](m: Map[K, V]): MapHasAsJava[K, V]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def MapHasAsScala[K, V](m: Map[K, V]): MapHasAsScala[K, V]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
implicit def MutableMapHasAsJava[K, V](m: Map[K, V]): MutableMapHasAsJava[K, V]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def MutableSeqHasAsJava[A](s: Seq[A]): MutableSeqHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def MutableSetHasAsJava[A](s: Set[A]): MutableSetHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def SeqHasAsJava[A](s: Seq[A]): SeqHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def SetHasAsJava[A](s: Set[A]): SetHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
implicit def SetHasAsScala[A](s: Set[A]): SetHasAsScala[A]

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala