Open In App

Scala SortedMap mkString() method with a separator with example

Last Updated : 02 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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 separator
import scala.collection.immutable.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
// Scala program of mkString()
// method with a separator
import scala.collection.immutable.SortedMap

// Creating object
object GfG
{ 

    // Main method
    def main(args:Array[String])
    {
    
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 5)
        
        // Applying mkString method 
        val result = m1.mkString("/")
        
        // Displays output
        println(result)
    }
}
Output:
for -> 3/geeks -> 5

Next Article
Article Tags :

Similar Reads