package com.wy
import scala.collection.mutable.ListBuffer
object ListDemo {
def main(args: Array[String]): Unit = {
//不可变List: 长度不可变,内容可变
var list: List[String] = List("Runoob", "Google", "Baidu")
//val list2 = "Runoob" :: ("Google" :: ("Baidu" :: Nil))
//增
list = list.+:("QQ")
list = list.:+("qq")
//改
list = list.updated(1,"QQ")
//删
list = list.drop(1)
for(li <- list){
println(li)
}
//可变ListBuffer:长度内容都可变 ListBuffer是链表结构,相当于java中的LinkedList
var lb:scala.collection.mutable.ListBuffer[String] = ListBuffer("zhangsan", "lisi", "wangwu")
//增
lb.insert(0,"zhaoliu")
//改
lb.update(0,"lisan")
//删
lb.remove(0)
for(list <- lb){
println(list)
}
}
}
Scala知识点10---List容器基本操作
最新推荐文章于 2021-05-08 20:31:34 发布