IT培訓(xùn)網(wǎng)
IT在線學(xué)習(xí)
3. ArrayBuffer上的常用操作
添加一個或多個元素:
+=
添加集合:
++=
刪除一個或多個元素:
-=
刪除集合元素:
--=
插入元素: 第一個參數(shù)是下標(biāo),第二個參數(shù)是一個可變參數(shù)列表,支持同時插入多個值
(n:Int,ele:Int*)
刪除元素:可以直接指定下標(biāo),還可以同時指定下標(biāo)和要刪除的元素個數(shù)
remove(n:Int)
remove(n:Int,count:Int)
清空集合:
clear
判空:
isEmpty
scala> ab
res8: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(1, 2, 3, 4, 5, 6)
scala> ab+=10
res9: ab.type = ArrayBuffer(1, 2, 3, 4, 5, 6, 10)
scala> ab+=(20,30)
res10: ab.type = ArrayBuffer(1, 2, 3, 4, 5, 6, 10, 20, 30)
scala> ab++=Array(5,6)
res11: ab.type = ArrayBuffer(1, 2, 3, 4, 5, 6, 10, 20, 30, 5, 6)
scala> ab-=1
res12: ab.type = ArrayBuffer(2, 3, 4, 5, 6, 10, 20, 30, 5, 6)
scala> ab-=(5,6)
res13: ab.type = ArrayBuffer(2, 3, 4, 10, 20, 30, 5, 6)
scala> ab--=Array(10,20,30)
res14: ab.type = ArrayBuffer(2, 3, 4, 5, 6)
scala> ab.(1,6,6,6)
scala> ab
res16: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(2, 6, 6, 6, 3, 4, 5, 6)
scala> ab.remove(3)
res17: Int = 6
scala> ab
res18: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(2, 6, 6, 3, 4, 5, 6)
scala> ab.remove(0,2)
scala> ab
res20: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(6, 3, 4, 5, 6)
scala> ab.isEmpty
res21: Boolean = false
scala> ab.clear
scala> ab.isEmpty
res23: Boolean = true
>>本文地址:http://liujunjsxg.cn/zhuanye/2021/70697.html
聲明:本站稿件版權(quán)均屬中公教育優(yōu)就業(yè)所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
1 您的年齡
2 您的學(xué)歷
3 您更想做哪個方向的工作?