Scala Mutable SortedMap mkString() method with example
The mkString() method is utilized to represent the elements of the SortedMap as a string.
Method Definition: def mkString: String
Return Type: It returns the elements of the SortedMap as a string.
Example #1:
// Scala program of mkString() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating SortedMap val m 1 = SortedMap( "Beginner" - > 5 , "for" - > 3 , "cs" - > 6 ) // Applying mkString method val result = m 1 .mkString // Displays output println(result) } } |
Output:
cs -> 6for -> 3Beginner -> 5
Example #2:
// Scala program of mkString() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating SortedMap val m 1 = SortedMap( "Beginner" - > 5 , "for" - > 3 , "for" - > 3 ) // Applying mkString method val result = m 1 .mkString // Displays output println(result) } } |
Output:
for -> 3Beginner -> 5