Open In App

Scala Queue +=:() method with example

Last Updated : 18 Oct, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The +=:() method is utilized to add an element at the front of a queue.
Method Definition: def +=:(elem: A): Queue.this.type Return Type: It returns the given queue with an element added at its front.
Example #1: Scala
// 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") 
        
        // Applying +=:() method 
        val result = q1.+=:("geeks")
        
        // Display output
        print(result)   
        
    } 
} 
Output:
Queue(geeks, for, geeks)
Example #2: Scala
// 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(2, 3, 4, 5) 
        
        // Applying +=:() method 
        val result = q1.+=:(1)
        
        // Display output
        print(result)   
        
    } 
} 
Output:
Queue(1, 2, 3, 4, 5)

Next Article

Similar Reads