Scala Queue ++() method with example
Last Updated :
24 Oct, 2019
The ++() method is utilized to return a new queue with all the elements of the queue appended at the back of another queue.
Method Definition: def ++[B >: A](suffix: IterableOnce[B]): Queue[B]
Return Type: It return a new queue with all the elements of the queue appended at the back of another queue.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 , 5 )
val q 2 = Queue( 11 , 12 , 13 , 14 , 15 )
val result = q 1 .++(q 2 )
print(result)
}
}
|
Output:
Queue(1, 2, 3, 4, 5, 11, 12, 13, 14, 15)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "geeks" )
val q 2 = Queue( "for" , "geeks" )
val result = q 1 ++ q 2
print(result)
}
}
|
Output:
Queue(geeks, for, geeks)
Share your thoughts in the comments
Please Login to comment...