带有示例的 Scala Queue +=() 方法
+=()方法用于在给定队列的后面添加一个元素。
Method Definition: def +=(elem: A): Queue.this.type
Return Type: It returns the given queue with an element added at its back.
示例 #1:
// Scala program of +=()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a queue
val q1 = Queue("geeks", "for")
// Applying +=() method
val result = q1.+=("geeks")
// Display output
print(result)
}
}
输出:
Queue(geeks, for, geeks)
示例 #2:
// Scala program of +=()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a queue
val q1 = Queue(1, 2, 3, 4)
// Applying +=() method
val result = q1.+=(5)
// Display output
print(result)
}
}
输出:
Queue(1, 2, 3, 4, 5)