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/scala.jdk.javaapi/CollectionConverters

CollectionConverters

scala.jdk.javaapi.CollectionConverters

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

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

Attributes

Source
CollectionConverters.scala
Graph
Supertypes
Self type

Members list

Value members

Inherited methods

defasJava[K,V](m:Map[K,V]):ConcurrentMap[K,V]

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.

Value parameters

m

The Scalaconcurrent.Map to be converted.

Attributes

Returns

A JavaConcurrentMap view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[K,V](m:Map[K,V]):Map[K,V]

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.

Value parameters

m

The ScalaMap to be converted.

Attributes

Returns

A JavaMap view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[K,V](m:Map[K,V]):Map[K,V]

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.

Value parameters

m

The Scala mutableMap to be converted.

Attributes

Returns

A JavaMap view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](s:Set[A]):Set[A]

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.

Value parameters

s

The ScalaSet to be converted.

Attributes

Returns

A JavaSet view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](s:Set[A]):Set[A]

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.

Value parameters

s

The Scala mutableSet to be converted.

Attributes

Returns

A JavaSet view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](s:Seq[A]):List[A]

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.

Value parameters

s

The ScalaSeq to be converted.

Attributes

Returns

A JavaList view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](s:Seq[A]):List[A]

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.

Value parameters

s

The ScalaSeq to be converted.

Attributes

Returns

A JavaList view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](b:Buffer[A]):List[A]

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.

Value parameters

b

The ScalaBuffer to be converted.

Attributes

Returns

A JavaList view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](i:Iterable[A]):Iterable[A]

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.

Value parameters

i

The ScalaIterable to be converted.

Attributes

Returns

A JavaIterable view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJava[A](i:Iterator[A]):Iterator[A]

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.

Value parameters

i

The ScalaIterator to be converted.

Attributes

Returns

A JavaIterator view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala

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.

Value parameters

i

The ScalaIterable to be converted.

Attributes

Returns

A JavaCollection view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala
defasJavaDictionary[K,V](m:Map[K,V]):Dictionary[K,V]

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.

Value parameters

m

The ScalaMap to be converted.

Attributes

Returns

A JavaDictionary view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala

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.

Value parameters

i

The ScalaIterator to be converted.

Attributes

Returns

A JavaEnumeration view of the argument.

Inherited from:
AsJavaConverters
Source
AsJavaConverters.scala

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.

Value parameters

p

The JavaProperties to be converted.

Attributes

Returns

A Scala mutableMap[String, String] view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[K,V](d:Dictionary[K,V]):Map[K,V]

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.

Value parameters

d

The JavaDictionary to be converted.

Attributes

Returns

A Scala mutableMap view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[K,V](m:ConcurrentMap[K,V]):Map[K,V]

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.

Value parameters

m

The JavaConcurrentMap to be converted.

Attributes

Returns

A Scala mutableConcurrentMap view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[K,V](m:Map[K,V]):Map[K,V]

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.

Value parameters

m

The JavaMap to be converted.

Attributes

Returns

A Scala mutableMap view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[A](s:Set[A]):Set[A]

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.

Value parameters

s

The JavaSet to be converted.

Attributes

Returns

A Scala mutableSet view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[A](l:List[A]):Buffer[A]

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.

Value parameters

l

The JavaList to be converted.

Attributes

Returns

A Scala mutableBuffer view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[A](c:Collection[A]):Iterable[A]

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.

Value parameters

c

The JavaCollection to be converted.

Attributes

Returns

A ScalaIterable view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[A](i:Iterable[A]):Iterable[A]

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.

Value parameters

i

The JavaIterable to be converted.

Attributes

Returns

A ScalaIterable view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala

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.

Value parameters

e

The JavaEnumeration to be converted.

Attributes

Returns

A ScalaIterator view of the argument.

Inherited from:
AsScalaConverters
Source
AsScalaConverters.scala
defasScala[A](i:Iterator[A]):Iterator[A]

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.

Value parameters

i

The JavaIterator to be converted.

Attributes

Returns

A ScalaIterator view of the argument.

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

[8]ページ先頭

©2009-2025 Movatter.jp