用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]
比如把Java的list快速转为scala的list
import scala.collection.JavaConversions val scalaList = JavaConversions.asScalaBuffer(javaList).toList |
把scala的Map转换成java.util.Map
import scala.collection.JavaConverters._
|