12_Scala_集合汇总
汇总待完善
|
创建 |
增 |
删 |
改 |
查 |
遍历 |
Array |
new Array[Int](3) Array(1, 2, 3)
|
array1(0) = 10
|
|
array1(0) = 20
|
array1(0) |
for (index <- 0 until array2.length)
|
ArrayBuffer |
ArrayBuffer[Int](1, 2, 3)
|
arraybuffer1.append(20)
|
arraybuffer1.remove(1)
|
|
|
For(item <- array1) |
|
|
|
|
|
|
|
List |
val list1 = List(1, 2, 3, "alex") val list2 = List(100) |
val list2_update1 = list2 :+ 1 返回一个新List val list2_update2 = 10 +: list2 var list3 = List(1,2) val list3_a = 3 :: list3 :: Nil val list3_b = 10 :: list3 ::: Nil |
|
|
list1(0) |
for (item <- list1){ println(item) } |
Listbuffer |
val listbuffer2 = new ListBuffer[Int] //空list val listbuffer1 = ListBuffer[Int](1, 2, 3) |
listbuffer2 += 4 listbuffer2.append(5) listbuffer2 ++= listbuffer1 //把listbuffer1的元素加到listbuffer2 |
listbuffer1.remove(0) |
listbuffer1(0) = 10 |
|
|
|
|
|
|
|
|
|
Queue |
new mutable.Queue[Any]() |
qu1 += 10 |
qu1.dequeue() 队首取数据 取出元素(弹出去) 自身变化 qu1.remove(1) |
qu1(1) =20 |
qu1.head |
|
Tuple |
tup1 = (10, 20, 30, "hello", 40) |
|
|
|
tup1._1 访问元祖第一个元素从1开始 |
|
Map |
Map("Alex" -> 30, "BoB" -> 40, "Robbin" -> 28) |
map5 += ("A" -> 100) |
map5 -= ("A", "B", "AAA") |
map5("A") = 20 |
map4("Alice") |
for ((k,v) <- map1) println(k + " map to " + v) |
set |
set_immut = Set(1, 2, 3) |
set_mutable.add(40) // 方法 |
set_mutable -= 10 //操作符形式 |
|
set_mutable(30) // 返回布尔,是否存在 |
for (i <- set_mutable) println(i ) |
|
|
|
|
|
|
for (item <- 0 to 3) //0123 for (item <- 0 until 3) //012
|
- 点赞
- 收藏
- 关注作者
评论(0)