scala集合和Java集合对应转换操作

用Scala编码的时候,经常会遇到scala集合和Java集合互相转换的case,

scala.collection.Iterable <=> java.lang.Iterable

scala.collection.Iterable <=> java.util.Collection

scala.collection.Iterator <=> java.util.{ Iterator, Enumeration }

scala.collection.mutable.Buffer <=> java.util.List

scala.collection.mutable.Set <=> java.util.Set

scala.collection.mutable.Map <=> java.util.{ Map, Dictionary }

scala.collection.mutable.ConcurrentMap <=> java.util.concurrent.ConcurrentMap

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

java.util.Properties => scala.collection.mutable.Map[String, String] 

 

可以用 scala.collection.JavaConversions来快速实现转换,比如把Java的list快速转为scala的list

val scalaList = JavaConversions.asScalaBuffer(javaList).toList

你可能感兴趣的:(scala集合和Java集合对应转换操作)