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) } } |
chevron_right
filter_none
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) } } |
chevron_right
filter_none
Output:
Queue(Geeks, Will, Rule) Queue: Geeks, Will, Rule
Recommended Posts:
- Scala Iterator mkString() method with a separator with example
- Scala Iterator mkString() method with a start, a separator and an end with example
- Scala Map mkString() method with a separator with example
- Scala Map mkString() method with a start, a separator and an end with example
- Scala List mkString() method with a separator with example
- Scala List mkString() method with a start, a separator and an end with example
- Scala Set mkString() method with a separator with example
- Scala SortedSet mkString() method with a separator with example
- Scala Stack mkString() method with a separator with example
- Scala SortedMap mkString() method with a separator with example
- Scala SortedMap mkString() method with a start, a separator and an end with example
- Scala TreeSet mkString() method with a separator with example
- Scala Mutable SortedMap mkString() method with a start, a separator and an end with example
- Scala Mutable SortedMap mkString() method with a separator with example
- Scala immutable TreeSet mkString() method with a separator
- Scala Queue mkString() method with example
- Scala Iterator mkString() method with example
- Scala Map mkString() method with example
- Scala List mkString() method with example
- Scala Set mkString() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

