标签:os 使用 java ar for sp c new r
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 Array[Array[Int]](2);
arr(0) = Array(1, 3)
arr(2) = new Array[Int](5)
var matrix = Array.ofDim[Int](2, 5) //二行,五列
matrix(0)(1) = 2 // 访问元素使用两个圆括号
标签:os 使用 java ar for sp c new r
原文地址:http://www.cnblogs.com/chanxiu/p/3972184.html