The mkString() method is utilized to display all the elements of the set in a string along with a separator.
Method Definition: def mkString(sep: String): String
Return Type: It returns all the elements of the set in a string along with a separator.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 )
val result = s 1 .mkString( ", " )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( "Geeks" , "Will" , "Rule" )
val result = s 1 .mkString( " " )
println(result)
}
}
|