package examples import scala.collection.mutable.ArrayBuffer object Example3 { def main(args: Array[String]) { val start = System.currentTimeMillis println("took " + (System.currentTimeMillis - start) + " ms") //定长数组Array val nums = new Array[Int](3) nums.foreach(println) val numArray = Array[Int](3,2) numArray.foreach(println) //变长数组ArrayBuffer val charArray = ArrayBuffer[Char]() charArray += 'H' charArray += 'i' charArray += (',','g') charArray ++= Array('i','r','l') charArray.foreach { println } charArray.trimEnd(5) //还有各种insert,remove等 val a = 0 until (10,3) println(a) val intArray = a.toArray val intArray2 = for(ele<-intArray if ele%2==0) yield 2*ele intArray2.foreach(println) val intArray3 = intArray.filter { _%2==0}.map { 2*_ } intArray3.foreach { println } println( intArray3.mkString("[", ",", "]")) val matrix = Array.ofDim[Double](3,4) //3行4列的数组 } }
took 54 ms 0 0 0 3 2 H i , g i r l Range(0, 3, 6, 9) 0 12 0 12 [0,12]
原文地址:http://blog.csdn.net/lingerlanlan/article/details/43280789