import scala.collection.immutable.Queue
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
object Test extends App{
//可变ListBuffer
val listBuffer = new ListBuffer[Int]
listBuffer += 1
listBuffer += 2
println(listBuffer)
//可变arrayBuffer
val arrayBuffer = new ArrayBuffer[Int]()
arrayBuffer += 1
arrayBuffer += 2
println(arrayBuffer)
//不可变Queue
val empty = Queue[Int]()
val queue1 = empty.enqueue(1)
val queue2 = queue1.enqueue(List(2, 3, 4, 5))
println(queue2)
//将第一个元素和后面的元素拆分成两个queue
val (element, left) = queue2.dequeue
println(element + " : " + left)
//可变的Queue
import scala.collection.mutable.Queue
val queue = Queue[String]()
queue += "a"
queue ++= List("b", "c")
println(queue)
println(queue.dequeue())
//可变的栈
import scala.collection.mutable.Stack
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.push(3)
println(stack.top)
println(stack)
println(stack.pop())
}
scala基础40-ListBuffer、ArrayBuffer、Queue、Stack
最新推荐文章于 2020-12-19 13:42:37 发布