Skip to content
Related Articles

Related Articles

Scala Map mkString() method with a start, a separator and an end with example
  • Last Updated : 26 Jul, 2019

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

Example #2:




// Scala program of mkString() method
// with a start, a separator and an
// end
  
// 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 -> 5|for -> 3--



My Personal Notes arrow_drop_up
Recommended Articles
Page :