Scala immutable TreeSet splitAt() method

In Scala immutable TreeSet class the splitAt() method is utilized to split the given TreeSet into a prefix/suffix pair of TreeSet at a stated position.

Method Definition: def splitAt(n: Int): (TreeSet[A], TreeSet[A])
Where, n is the position at which we need to split.

Return Type: It returns a pair of TreeSet consisting of the first n elements of this TreeSet, and the other elements.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of splitAt() 
// method 
  
// Import TreeSet
import scala.collection.immutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating TreeSet
        val t1 = TreeSet(3, 1, 5, 2, 4)  
            
        // Print the TreeSet 
        println(t1
          
        // Applying splitAt method  
        val result = t1.splitAt(2)
            
        // Displays output  
        print(result) 
          
    

chevron_right


Output:

TreeSet(1, 2, 3, 4, 5)
(TreeSet(1, 2), TreeSet(3, 4, 5))

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of splitAt() 
// method 
  
// Import TreeSet
import scala.collection.immutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating TreeSet
        val t1 = TreeSet(3, 1, 5, 2, 4)  
            
        // Print the TreeSet 
        println(t1
          
        // Applying splitAt method  
        val result = t1.splitAt(3)
            
        // Displays output  
        print(result) 
          
    

chevron_right


Output:

TreeSet(1, 2, 3, 4, 5)
(TreeSet(1, 2, 3), TreeSet(4, 5))



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.