Scala Queue ++() 方法与示例
++()方法用于返回一个新队列,该队列的所有元素都附加在另一个队列的后面。
Method Definition: def ++[B >: A](suffix: IterableOnce[B]): Queue[B]
Return Type: It return a new queue with all the elements of the queue appended at the back of another queue.
示例 #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(1, 2, 3, 4, 5)
val q2 = Queue(11, 12, 13, 14, 15)
// Applying ++() method
val result = q1.++(q2)
// Display output
print(result)
}
}
输出:
Queue(1, 2, 3, 4, 5, 11, 12, 13, 14, 15)
示例 #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("geeks")
val q2 = Queue("for", "geeks")
// Applying ++() method
val result = q1 ++ q2
// Display output
print(result)
}
}
输出:
Queue(geeks, for, geeks)