数组的定义
scala> val arr = Array(1,2,3)
arr: Array[Int] = Array(1, 2, 3)
//自动推断初始化类型
//也可以指定类型
scala> val arr = Array[Int](1,2,3)
arr: Array[Int] = Array(1, 2, 3)
val arr2 = new Array[Int](10)//10代表数组长度,没办法初始化
arr2: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
数组的访问
数组的常用方法
scala> arr2.sum
res85: Int = 2
scala> arr2.max
res86: Int = 2
scala> arr2.min
res87: Int = 0
scala> arr2.sorted
res88: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 2)
scala> arr2.sorted.reverse
res89: Array[Int] = Array(2, 0, 0, 0, 0, 0, 0, 0, 0, 0)