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