Scala二维数组的定义:
val arr2 = Array.ofDim[String](2, 2) arr2(0)(0) = "aa" arr2(1)(0) = "bb" for(i <- 0 until arr2.length; j <- 0 until arr2(0).length){ println(arr2(i)(j)) }
Scala不规则数组定义:
val tri = new Array[Array[Int]](2) tri(0) = new Array[Int](2) tri(1) = new Array[Int](5)
当我们Scala调用java方法时,这个方法可能接受的是java 集合比如java.util.List, 我们完全可以引入scala.collection.JavaConversions里面的隐式转换方法。
val command = ArrayBuffer("aa", "bb") import scala.collection.JavaConversions.bufferAsJavaList val pb = new ProcessBuilder(command) import scala.collection.JavaConversions.asScalaBuffer val cmd: Buffer[String] = pb.command()
ProcessBuilder构造需要java.util.List对象,我们通过导入隐式转换,ArrayBuffer对象会自动转换为java.util.List对象,反之pb.command()返回的是java.util.List对象,通过隐式转换,自动转换为Buffer对象。