Scala Queue +=() method with example
Last Updated :
18 Oct, 2019
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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "geeks" , "for" )
val result = q 1 .+ = ( "geeks" )
print(result)
}
}
|
Output:
Queue(geeks, for, geeks)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 )
val result = q 1 .+ = ( 5 )
print(result)
}
}
|
Output:
Queue(1, 2, 3, 4, 5)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...