Scala TreeSet toSeq() method with example
Last Updated :
11 Nov, 2019
The toSeq() method is utilized to return a seq consisting of all the elements of the TreeSet.
Method Definition: def toSeq: Seq[A]
Return Type: It returns a seq consisting of all the elements of the TreeSet.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 1 , 2 , 3 , 4 , 5 , 6 )
println(t 1 )
val result = t 1 .toSeq
print( "Elements in the Seq: " )
for (ele < - result)
print(ele + " " )
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5, 6)
Elements in the Seq: 1 2 3 4 5 6
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 .toSeq
print( "Elements in the Seq: " )
for (ele < - result)
print(ele + " " )
}
}
|
Output:
TreeSet(a, e, i, o, u)
Elements in the Seq: a e i o u
Share your thoughts in the comments
Please Login to comment...