Skip to content
Related Articles

Related Articles

Scala SortedMap mkString() method with example
  • Last Updated : 02 Nov, 2019

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.immutable.SortedMap
  
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 6)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}
Output:
cs -> 6for -> 3geeks -> 5

Example #2:




// Scala program of mkString()
// method
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, "for" -> 3)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}
Output:
for -> 3geeks -> 5



My Personal Notes arrow_drop_up
Recommended Articles
Page :