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