Open In App

Scala Mutable SortedMap mkString() method with a start, a separator and an end with example

Improve
Improve
Like Article
Like
Save
Share
Report

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 SortedMap as a string along with a stated start, separator and an end.

Example #1:




// Scala program of mkString() method
// with a start, a separator and an
// end
import scala.collection.SortedMap
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 2)
          
        // Applying mkString method 
        val result = m1.mkString(">>>", "|", "--")
          
        // Displays output
        println(result)
    }
}


Output:

>>>cs -> 2|for -> 3|geeks -> 5--

Example #2:




// Scala program of mkString() method
// with a start, a separator and an
// end
import scala.collection.SortedMap
  
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "for" -> 3)
          
        // Applying mkString method 
        val result = m1.mkString(">>>", "|", "--")
          
        // Displays output
        println(result)
    }
}


Output:

>>>for -> 3|geeks -> 5--


Last Updated : 04 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads