频道栏目
首页 > 网络 > 云计算 > 正文

scala数组ArrayBuffer解析

2018-09-28 10:00:43           
收藏   我要投稿

scala> import scala.collection.mutable.ArrayBuffer

import scala.collection.mutable.ArrayBuffer

scala> val arrBuffer=ArrayBuffer[Int]() arrBuffer: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()

scala> arrBuffer+=10 res6: arrBuffer.type = ArrayBuffer(10)

scala> arrBuffer res7: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10)

scala> arrBuffer+=(11,1,3,4,5) res8: arrBuffer.type = ArrayBuffer(10, 11, 1, 3, 4, 5)

scala> arrBuffer++=Array(1,2,3,4) res9: arrBuffer.type = ArrayBuffer(10, 11, 1, 3, 4, 5, 1, 2, 3, 4)

scala> arrBuffer.trim trimEnd trimStart scala> arrBuffer.trimEnd(3)

scala> arrBuffer res11: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 5, 1)

scala> arrBuffer.insert(5,100)

scala> arrBuffer res13: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 5, 1)

scala> arrBuffer.insert(7,9,2,444,5)

scala> arrBuffer res15: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 5, 9, 2, 444, 5, 1)

scala> arrBuffer.remove(10) res16: Int = 5

scala> arrBuffer res17: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 5, 9, 2, 444, 1)

scala> arrBuffer.remove(6) res18: Int = 5

scala> arrBuffer res19: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 9, 2, 444, 1)

scala> arrBuffer.remove(6,3) scala> arrBuffer res25: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 1) scala> arrBuffer.toArray res26: Array[Int] = Array(10, 11, 1, 3, 4, 100, 1)

scala> val arr2=arrBuffer.toArray arr2: Array[Int] = Array(10, 11, 1, 3, 4, 100, 1)

scala> arr2.toBuffer res27: scala.collection.mutable.Buffer[Int] = ArrayBuffer(10, 11, 1, 3, 4, 100, 1)

上一篇:Elasticsearch5安装bigdesk解析
下一篇:clusterProfiler安装或者升级中出现的版本问题
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站