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