scala入门初级代码训练-37listBufferArrayBufferQueueStack
原创文章,转载请注明出处!
原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-37/
There I am,in the world more exciting!
package com.ptbird.scala
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
/**
* Created by postbird on 2016/5/26.
*/
object ListArrayQueueStackBuffer {
def main(args: Array[String]): Unit = {
val listBuffer = new ListBuffer[Int]
listBuffer += 1
listBuffer += 1
println(listBuffer)
//ListBuffer(1, 1)
val arrayBuffer = new ArrayBuffer[Int]()
arrayBuffer += 1
arrayBuffer += 2
arrayBuffer.foreach(print) //12
import scala.collection.mutable.Queue
val queue = Queue[String]()
queue += "aa"
queue ++= List("bb", "cc")
println(queue)
println(queue.dequeue()) //出队操作
println(queue)
// Queue(aa, bb, cc)
// aa
// Queue(bb, cc)
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)
println(stack)
// 3
// Stack(3, 2, 1)
// 3
// Stack(2, 1)
}
}
文章已经结束啦
文章版权:Postbird-There I am , in the world more exciting!
本文链接:http://www.ptbird.cn/scala-chuji-demo-37.html
转载请注明文章原始出处 !
扫描二维码,在手机阅读!