首页  

scala java 集合类型转换     所属分类 scala 浏览量 260
注意 JavaConverters._   不要忘了 ._ !!!
import scala.collection.JavaConverters._

scala2.12开始,废除 scala.collection.JavaConversions ,
改用 scala.collection.JavaConverters


val list = new java.util.ArrayList[Int]()
list: java.util.ArrayList[Int] = []

list.add(1)

list.asScala
res17: scala.collection.mutable.Buffer[Int] = Buffer(1)

val a = List(1,2,3)
a: List[Int] = List(1, 2, 3)

a.asJava
res18: java.util.List[Int] = [1, 2, 3]

val seq = Seq(1,2,3)
seq: Seq[Int] = List(1, 2, 3)

seq.asJava
res19: java.util.List[Int] = [1, 2, 3]



val list = List(1,2) list: List[Int] = List(1, 2) scala> list.asJava res0: java.util.List[Int] = [1, 2] scala> val javaList = list.asJava javaList: java.util.List[Int] = [1, 2] scala> javaList.asScala res1: scala.collection.mutable.Buffer[Int] = Buffer(1, 2) scala> javaList.asScala.toList res2: List[Int] = List(1, 2) javaList.asScala.toList(0) res5: Int = 1 javaList.asScala.toSeq res3: Seq[Int] = Buffer(1, 2) javaList.asScala.toSeq(0) res4: Int = 1

上一篇     下一篇
java scala 从 queryStringMap 获取参数值

Scala 集合 sliding与grouped

Scala 集合 拆分操作 partition groupBy grouped sliding

scala getClass和classOf

WEB3.0简介

eclipse启动失败 failed to create the java virtual machine