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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 , 5 )
val res = q 1 . : +( 10 )
print(res)
}
}
|
Output:
Queue(1, 2, 3, 4, 5, 10)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "geeks" , "for" )
val res = q 1 . : +( "geeks" )
print(res)
}
}
|
Output:
Queue(geeks, for, geeks)
Share your thoughts in the comments
Please Login to comment...