val nums = new Array[Int](10)
val b = new ArrayBuffer[Int] 或 ArrayBuffer[Int]()
b.+=1
b.+= (2, 3, 4)
b.++= Array(5, 6, 7, 8)
b.trimEnd(3)
b.insert(2, 3)
b.insert(2, 3, 4, 5)
b.remove(2)
b.remove(2, 4)
b.toArray
for (i <- 0 until b.length)
println(b(i))
for (i <- (0 until b.lenght).reverse)
println(b(i))
for (element <- b)
println(element)
val a = Array(1, 2, 3, 4)
val b = for (e <- a) yield e * 2
val b = a.map(_ * 2)
val c = for (e <- a if e % 2 == 0) yield 2*e
val c = a.filter(%2==0).map(2*)
sum:必须是数值型类型
min
max
sorted:
scala.util.Sorting.quickSort(a)
mkString
toString
创建维度不同的二维数组:
var arr = new ArrayArray[Int]; arr(0) = Array(1, 3) arr(2) = new ArrayInt
创建维度相同的数组:
var matrix = Array.ofDimInt //二行,五列
matrix(0)(1) = 2 // 访问元素使用两个圆括号