首页 > 代码库 > Scala 数组-Array

Scala 数组-Array

环境: CentOS 6.3

 

1. 定义且同时初始化数组

$ cat array.scalaval numNames2 = Array.apply("France","US","china")println(numNames2(0))[hadoop@localhost scala]$ scala array.scalaFrance

Array.apply("France","US","china") 等价于 Array("France","US","china")

2. 定义数组大小,然后初始化

$ cat array_init.scalavar array_init = new Array[String](3)array_init(0) = "this "array_init.update(1,"is ")array_init.update(2,"china")array_init.foreach(println)$ scala array_init.scalathis is china

array_init.update(2,"china") 等价于 array_init(2) = "china"