Scala Map mkString() method with a separator with example
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 map as a string along with the separator between them.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = Map( "geeks" - > 5 , "for" - > 3 , "cs" - > 2 )
val result = m 1 .mkString( "/" )
println(result)
}
}
|
Output:
geeks -> 5/for -> 3/cs -> 2
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = Map( "geeks" - > 5 , "for" - > 3 , "geeks" - > 5 )
val result = m 1 .mkString( "/" )
println(result)
}
}
|
Output:
geeks -> 5/for -> 3
Last Updated :
26 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...