Scala 학습 노트 - 06 - 데이터 구조 - list Buffer 와 Array Buffer

1462 단어
ListBuffer, + = insert, - = remove
scala> import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ListBuffer
//   ListBuffer
scala> val mutList1 = ListBuffer(10,20,30)
mutList1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30)
//  mutList1   ,  50   
scala> mutList1 += 50
res58: mutList1.type = ListBuffer(10, 20, 30, 50)

scala> mutList1
res59: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30, 50)
//  mutList1     60  ,       List, mutList1  
scala> mutList1 :+ 60
res60: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30, 50, 60)

scala> mutList1
res61: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30, 50)

scala> res60
res62: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30, 50, 60)
// mutList1   ,          60  
scala> mutList1.insert(2,100)

scala> mutList1
res64: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 100, 30, 50)
// mutList1   ,       100
scala> mutList1 -= 100
res65: mutList1.type = ListBuffer(10, 20, 30, 50)

scala> mutList1
res66: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30, 50)
//  mutList1   ,     3   
scala> mutList1.remove(3)
res68: Int = 50

scala> mutList1
res69: scala.collection.mutable.ListBuffer[Int] = ListBuffer(10, 20, 30)

 
 
----

좋은 웹페이지 즐겨찾기