Scala immutable TreeSet mkString() method with a separator
Last Updated :
19 Apr, 2020
In Scala immutable TreeSet class the mkString() method is utilised to display all the elements of the TreeSet in a string along with a separator.
Method Definition: def mkString(sep: String): String
Return Type: It returns all the elements of the TreeSet in a string along with a separator.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 3 , 1 , 5 , 2 , 4 )
println(t 1 )
val result = t 1 .mkString( ", " )
print( "TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
TreeSet: 1, 2, 3, 4, 5
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( "u" , "a" , "i" , "o" , "e" )
println(t 1 )
val result = t 1 .mkString( ", " )
print( "TreeSet: " + result)
}
}
|
Output:
TreeSet(a, e, i, o, u)
TreeSet: a, e, i, o, u
Share your thoughts in the comments
Please Login to comment...