Open In App

Scala Queue mkString() method with a separator with example

Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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 q1 = Queue(1, 2, 3, 4
          
        // Print the queue
        println(q1)
          
        // Applying mkString method 
        val result = q1.mkString(", ")
          
        // Display output
        print("Queue: " + result)
          
    


Output:

Queue(1, 2, 3, 4)
Queue: 1, 2, 3, 4

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 q1 = Queue("Geeks", "Will", "Rule"
          
        // Print the queue
        println(q1)
          
        // Applying mkString method 
        val result = q1.mkString(", ")
          
        // Display output
        print("Queue: " + result)
          
    


Output:

Queue(Geeks, Will, Rule)
Queue: Geeks, Will, Rule


Last Updated : 29 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads