总共分为Array和ArrayBuffer,这里的操作参数很多,很难说的完整,这里就说几个常用的。建议先看博客中的List的部分,因为Array这一部分很多都是一样的。
scala> val a=Array(1,2,3)
a: Array[Int] = Array(1, 2, 3)
scala> a:+(4)
res100: Array[Int] = Array(1, 2, 3, 4)
scala> a.:+(4)
res101: Array[Int] = Array(1, 2, 3, 4)
scala> a.+:(0)
res105: Array[Int] = Array(0, 1, 2, 3)
scala> a++:Array(4,5,6)
res104: Array[Int] = Array(1, 2, 3, 4, 5, 6)
scala> a.drop(2)
res107: Array[Int] = Array(3)
scala> a.dropRight(2)
res108: Array[Int] = Array(1)
scala> a.sorted.reverse
res111: Array[Int] = Array(3, 2, 1)
scala> val a=ArrayBuffer(1,2,3)
a: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3)
-尾端加元素
scala> a+=(4)
res112: a.type = ArrayBuffer(1, 2, 3, 4)
scala> 0+:(a)
res113: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(0, 1, 2, 3, 4)
scala> a.drop(2)
res114: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(3, 4)
scala> a.dropRight(2)
res116: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2)
scala>
scala> a.sorted
res117: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3, 4)
scala>
其中关于Array和ArrayBuffer的区别的话,还是一样吧,都是效率问题