object ListDemo { def main(args: Array[String]): Unit = { //ListBuffer val listBuffer = ListBuffer(1,2,3) val listBuffer1 = ListBuffer(88,99) //添加元素,可变集合,list本身发生变化,而不是返回新的list listBuffer += 4 listBuffer.append(5,6) //添加整个集合(扁平) listBuffer ++= listBuffer1 //++=的展开写法,需要接收返回值,也是ListBuffer val listBuffer2 = listBuffer ++ listBuffer1 println(listBuffer) println(listBuffer2) //ListBuffer也支持不可变List的操作。同样返回值也是ListBuffer val listBuffer3 = listBuffer :+ 100 println(listBuffer3) } }