Scala Stack mkString() method with a separator with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala Stack class, the mkString() method is utilized to display all the elements of the stack in a string along with a separator. Method Definition: def mkString(sep: String): String Return Type: It returns all the elements of the stack in a string along with a separator. Example #1: Scala // Scala program of mkString() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(1, 2, 3, 4) // Print the stack println(s1) // Applying mkString method val result = s1.mkString(", ") // Display output print("Stack: " + result) } } Output: Stack(1, 2, 3, 4) Stack: 1, 2, 3, 4 Example #2: Scala // Scala program of mkString() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack("Geeks", "for", "Geeks") // Print the stack println(s1) // Applying mkString method val result = s1.mkString(", ") // Display output print("Stack: " + result) } } Output: Stack(Geeks, for, Geeks) Stack: Geeks, for, Geeks Comment More infoAdvertise with us Next Article Scala Stack mkString() method with a separator with example rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set mkString() method with a separator with example The mkString() method is utilized to display all the elements of the set in a string along with a separator. Method Definition: def mkString(sep: String): String Return Type: It returns all the elements of the set in a string along with a separator. Example #1: Scala // Scala program of mkString() / 1 min read Scala SortedMap mkString() method with a separator with example This method is same as mkString() method but here a separator is also added. Method Definition: def mkString(sep: String): String Return Type: It returns the elements of the SortedMap as a string along with the separator between them. Example #1: Scala // Scala program of mkString() // method with a 1 min read Scala TreeSet mkString() method with a separator with example The mkString() method is utilized to display all the elements of the TreeSet in a string along with a separator. Method Definition: def mkString(sep: String): String Return Type: It returns all the elements of the TreeSet in a string along with a separator. Example #1: Scala // Scala program of mkSt 1 min read Scala SortedSet mkString() method with a separator with example The mkString() method is utilized to display all the elements of the SortedSet in a string along with a separator. Method Definition: def mkString(sep: String): String Return Type: It returns all the elements of the SortedSet in a string along with a separator. Example #1: Scala // Scala program of 1 min read Scala Map mkString() method with a separator with example This method is same as mkString() method but here a separator is also added. Method Definition: def mkString(sep: String): String Return Type: It returns the elements of the map as a string along with the separator between them. Example #1: Scala // Scala program of mkString() // method with a separ 1 min read Scala List mkString() method with a separator with example The mkString() method is utilized to display all the elements of the list in a string along with a separator. Method Definition: def mkString(sep: String): String Return Type: It returns all the elements of the list in a string along with a separator. Example #1: Scala // Scala program of mkString() 1 min read 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: Scala // Scala program of mkString 1 min read Scala Iterator mkString() method with a separator with example This method is same as mkString() method but here a separator is included. Method Definition: def mkString(sep: String): String Return Type: It returns the string representation of the stated collection with a given separator. Example #1: Scala // Scala program of mkString() // method with a separat 1 min read Scala Mutable SortedMap mkString() method with a separator with example This method is same as mkString() method but here a separator is also added. Method Definition: def mkString(sep: String): String Return Type: It returns the elements of the SortedMap as a string along with the separator between them. Example #1: Scala // Scala program of mkString() // method with a 1 min read Scala Map mkString() method with a start, a separator and an end with example This method is same as mkString() but here a start, a separator, and an end is also added. Method Definition: defmkString(start: String, sep: String, end: String): String Return Type: It returns the elements of the map as a string along with a stated start, separator and an end. Example #1: Scala // 1 min read Like