Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Scala Map mkString() method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The mkString() method is utilized to represent the elements of the map as a string.

Method Definition: def mkString: String

Return Type: It returns the elements of the map as a string.

Example #1:




// Scala program of mkString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating map
        val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 6)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}


Output:

geeks -> 5for -> 3cs -> 6

Example #2:




// Scala program of mkString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating map
        val m1 = Map("geeks" -> 5, "for" -> 3, "for" -> 3)
          
        // Applying mkString method 
        val result = m1.mkString
          
        // Displays output
        println(result)
    }
}


Output:

geeks -> 5for -> 3

My Personal Notes arrow_drop_up
Last Updated : 26 Jul, 2019
Like Article
Save Article
Similar Reads