Scala Queue mkString() method with example
The mkString() method is utilized to display all elements of the queue in a string.
Method Definition: def mkString: String
Return Type: It returns a string containing all the element of the queue.
Example #1:
// Scala program of mkString() // method // Import Queue import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a queue val q 1 = Queue( 1 , 2 , 3 , 4 ) // Print the queue println(q 1 ) // Applying mkString method val result = q 1 .mkString // Display output print( "Queue: " + result) } } |
Output:
Queue(1, 2, 3, 4) Queue: 1234
Example #2:
// Scala program of mkString() // method // Import Queue import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a queue val q 1 = Queue( "Geeks" , "Will" , "Rule" ) // Print the queue println(q 1 ) // Applying mkString method val result = q 1 .mkString // Display output print( "Queue: " + result) } } |
Output:
Queue(Geeks, Will, Rule) Queue: GeeksWillRule