scala 可变列表与不可变链表
package com.cslc.day2 object listApp { def main(args: Array[String]): Unit = { val l=List(1,2,3,4,5) println(l.head) println(l.tail) //list 头部新增 val l2=1::Nil println(l2) //可变的列表 val cl1=scala.collection.mutable.ListBuffer[Int]() cl1+=1 cl1+=2 println(cl1) cl1++=List(8,9,8,98,9,9) println(cl1) //插入 cl1.insert(2,100,101,102) println(cl1) cl1.append(999,998) println(cl1) //删除 cl1.remove(1,2) println(cl1) cl1.trimEnd(2) println(cl1) println(SUM(1,2,3,4)) } def SUM(nums:Int*): Int ={ if (nums.length==0){ 0 }else{ nums.head+SUM(nums.tail:_*) } } }