Scala Queue mkString() method with a separator with example
The mkString() method is utilized to display all the elements of the queue in a string along with a separator.
Method Definition: def mkString(sep: String): String
Return Type: It returns all the elements of the queue in a string along with a separator.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 )
println(q 1 )
val result = q 1 .mkString( ", " )
print( "Queue: " + result)
}
}
|
Output:
Queue(1, 2, 3, 4)
Queue: 1, 2, 3, 4
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "Geeks" , "Will" , "Rule" )
println(q 1 )
val result = q 1 .mkString( ", " )
print( "Queue: " + result)
}
}
|
Output:
Queue(Geeks, Will, Rule)
Queue: Geeks, Will, Rule
Last Updated :
29 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...