The mkString() method is utilized to display all elements of the TreeSet in a string.
Method Definition: def mkString: String
Return Type: It returns a string containing all the element of the TreeSet.
Example #1:
import scala.collection.mutable. _
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: 12345
Example #2:
import scala.collection.mutable. _
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: aeiou