Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.jdk/CollectionConverters

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 injavaapi.CollectionConverters instead.

Note: to createJava Streams that operate on Scala collections (sequentially or in parallel), useStreamConverters.

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.asJavajs: java.util.Set[String] = [one]scala> js.add("two")scala> sres2: scala.collection.mutable.Set[String] = HashSet(two, one)

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.ConcurrentMap

The following conversions are supported viaasScala 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 viaasJava:

scala.collection.Seq         => java.util.Listscala.collection.mutable.Seq => java.util.Listscala.collection.Set         => java.util.Setscala.collection.Map         => java.util.Map

The following one way conversion is provided viaasScala:

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.asJavaval other: scala.collection.mutable.Buffer[Int] = target.asScalaassert(source eq other)

Attributes

Source
CollectionConverters.scala
Graph
Supertypes
Self type

Members list

Type members

Inherited classlikes

implicitclassBufferHasAsJava[A](b:Buffer[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassCollectionHasAsScala[A](c:Collection[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassConcurrentMapHasAsJava[K,V](m:Map[K,V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassConcurrentMapHasAsScala[K,V](m:ConcurrentMap[K,V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassDictionaryHasAsScala[K,V](d:Dictionary[K,V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassEnumerationHasAsScala[A](e:Enumeration[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassIterableHasAsJava[A](i:Iterable[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassIterableHasAsScala[A](i:Iterable[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassIteratorHasAsJava[A](i:Iterator[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassIteratorHasAsScala[A](i:Iterator[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassListHasAsScala[A](l:List[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassMapHasAsJava[K,V](m:Map[K,V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassMapHasAsScala[K,V](m:Map[K,V])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassMutableMapHasAsJava[K,V](m:Map[K,V])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassMutableSeqHasAsJava[A](s:Seq[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassMutableSetHasAsJava[A](s:Set[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassSeqHasAsJava[A](s:Seq[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassSetHasAsJava[A](s:Set[A])

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala
Supertypes
classObject
traitMatchable
classAny
implicitclassSetHasAsScala[A](s:Set[A])

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
Supertypes
classObject
traitMatchable
classAny

Implicits

Inherited implicits

implicitdefBufferHasAsJava[A](b:Buffer[A]):BufferHasAsJava[A]

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

Inherited from:
AsJavaExtensions
Source
AsJavaExtensions.scala

Attributes

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

Attributes

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

Attributes

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

Attributes

Inherited from:
AsScalaExtensions
Source
AsScalaExtensions.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp