Scala Queue :+() method with example
The :+() method is utilized to return a new queue with an element added at the back of the given queue.
Method Definition: def:+[B >: A](elem: B): Queue[B]
Return Type: It returns a new queue with an element added at the back of the given 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 q 1 = Queue( 1 , 2 , 3 , 4 , 5 ) // Applying :+() method val res = q 1 . : +( 10 ) // Display output print(res) } } |
Output:
Queue(1, 2, 3, 4, 5, 10)
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 q 1 = Queue( "Beginner" , "for" ) // Applying :+() method val res = q 1 . : +( "Beginner" ) // Display output print(res) } } |
Output:
Queue(Beginner, for, Beginner)
Contact Us