The mkString() method is utilized to display all the elements of the list in a string along with a separator.
Method Definition: def mkString(sep: String): String
Return Type: It returns all the elements of the list in a string along with a separator.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 2 , 3 , 5 , 7 , 8 )
val result = m 1 .mkString( "*" )
println(result)
}
}
|
Example: 2#
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 2 , 3 , 5 , 7 , 5 )
val result = m 1 .mkString( "_" )
println(result)
}
}
|