数组属于可变类型,因为虽然它不能被赋予另外一个数组,但它的元素的值可以改变。
1. 定义:
val greetStrings=new Array[String](3)
greetString(0) = "Hello"
greetString(1) = ","
greetString(2) = "world"
或
val numNames = Array("zero","one","two")
val numNames2 = Array.apply("zero","one","two")
2. 遍历:
for( i <- 0 to 2)
print(greetString(i))
或者转化为
for( i <- 0.to(2) )
print(greetString.apply(i))