Scala Queue ++:() method with example
The ++:() method is utilized to return a new queue with all the elements of the queue appended at the front of another queue.
Method Definition: def ++:[B >: A](prefix: IterableOnce[B]): Queue[B]
Return Type: It returns a new queue with all the elements of the queue appended at the front of another queue.
Example #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) } } |
Output:
Queue(11, 12, 13, 14, 15, 1, 2, 3, 4, 5)
Example #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("for", "geeks") val q2 = Queue("geeks") // Applying ++:() method val result = q1.++:(q2) // Display output print(result) } } |
Output:
Queue(geeks, for, geeks)

