1、说明:
scala的集合中有两种List:
scala.collection.immutable.List //长度内容都不可变
scala.collection.mutable.ListBuffer //长度内容都可变,必须导入包
注意:immutable下没有ListBuffer;mutable下没有List;
2、List
val list = List(1, 2, 3)
val list02 = "Hello" :: list
println(list02.mkString(",")) //Hello,1,2,3
val list03 = list :+ 6
println(list03.mkString(","))//1,2,3,6
val list04 = 6 +: list
println(list04.mkString(","))//6,1,2,3
3、ListBuffer
val listBuf= ListBuffer(5,6,7,8)
val listBuffer= new ListBuffer[Int]()
listBuffer.append(5)
listBuffer.append(6)
listBuffer.append(7)
listBuffer.append(8)
listBuffer += 9
listBuffer -= 5
println(listBuffer.mkString(",")) //6,7,8,9