Conversion of Scala collection types to Java

Source: Internet
Author: User

The Scala collection and the Java collection type convert to each other:

http://www.scala-lang.org/api/current/index.html#scala.collection.javaconverters$


You can easily convert between Java and Scala collection types through the Javaconverters package. It asScala decorates the Scala collection with a method of decorating the common Java collection asJava .

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)

Bidirectional conversions:

scala.collection.iterable <=> java.lang.iterablescala.collection.iterable <=>  java.util.collectionscala.collection.iterator <=> java.util. { iterator, enumeration }scala.collection.mutable.buffer <=>  java.util.listscala.collection.mutable.set <=> java.util.setscala.collection.mutable.map  <=> java.util. { map, dictionary }scala.collection.mutable.concurrentmap <=>  Java.util.concurrent.ConcurrentMap 

In addition, the following one-way conversions are provided

Scala.collection.Seq = Java.util.Listscala.collection.mutable.Seq = Java.util.Listscala.collection.Set = > Java.util.Setscala.collection.Map = Java.util.Map


This article from the "Down-to-earth, look at the Stars" blog, please be sure to keep this source http://xubcing.blog.51cto.com/3502962/1670030

Conversion of Scala collection types to Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.