Scala TreeSet toSeq() method with example
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:
// Scala program of toSeq() // method // Import TreeSet import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating TreeSet val t 1 = TreeSet( 1 , 2 , 3 , 4 , 5 , 6 ) // Print the TreeSet println(t 1 ) // Applying toSeq method val result = t 1 .toSeq // Display output 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:
// Scala program of toSeq() // method // Import TreeSet import scala.collection.mutable. _ // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating TreeSet val t 1 = TreeSet( "u" , "a" , "i" , "o" , "e" ) // Print the TreeSet println(t 1 ) // Applying toSeq method val result = t 1 .toSeq // Display output 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
Please Login to comment...