scala的多种集合的使用(8)之队列和栈的操作方法

队列是一种那个先进先出的队列
1)创建一个队列。

scala> import scala.collection.mutable.Queue import scala.collection.mutable.Queue scala> var fruits = Queue[String]() fruits: scala.collection.mutable.Queue[String] = Queue() scala> fruits += "apple" res66: scala.collection.mutable.Queue[String] = Queue(apple) scala> fruits += ("orange","banana") res67: scala.collection.mutable.Queue[String] = Queue(apple, orange, banana) scala> fruits ++= List("cherry","cocount") res68: scala.collection.mutable.Queue[String] = Queue(apple, orange, banana, cherry, cocount) scala> fruits.enqueue("pine") scala> fruits res70: scala.collection.mutable.Queue[String] = Queue(apple, orange, banana, cherry, cocount, pine)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzsgdx.html