Scala List mkString() method with a start, a separator and an end with example
This method is same as mkString() method but here a start, a separator and an end is also included.
Method Definition: defmkString(start: String, sep: String, end: String): String
Return Type: It returns the elements of the list as a string along with a stated start, separator and an end.
Let’s check some examples.
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)
}
}
|
Last Updated :
13 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...