The operation xs mkString (pre, sep, post) involves four operands: the list xstobedisplayed,aprefixstringpretobedisplayedinfrontofallelements, a separator string sep to be displayed between successive elements, and a postfix string post to be displayed at the end. The result of the operation is the string:
pre + xs(0) + sep + …+ sep + xs(xs.length – 1) + post
The mkString method has two overloaded variants that let you drop some or all of its arguments. The first variant only takes a separator string:
xs mkString sep equals xs mkString (“”, sep, “”)
The second variant lets you omit all arguments:
xs.mkString equals xs mkString “”
object List_mkstring extends App{
val lst=List(1,2,3)
println(lst.mkString("##","*","&&"))
println(lst mkString "#")
println(lst mkString)
}
##1*2*3&&
1#2#3
123