Related Articles

Related Articles

Scala Queue :+() method with example
  • Last Updated : 18 Oct, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
          
        // Applying :+() method 
        val res = q1.:+(10)
          
        // Display output
        print(res)   
          
    

chevron_right


Output:

Queue(1, 2, 3, 4, 5, 10)

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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", "for")
          
        // Applying :+() method 
        val res = q1.:+("geeks")
          
        // Display output
        print(res)   
          
    

chevron_right


Output:

Queue(geeks, for, geeks)



My Personal Notes arrow_drop_up
Recommended Articles
Page :