Open In App

Scala Mutable SortedSet splitAt() method

Last Updated : 26 Mar, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
In Scala mutable collections, splitAt() method is utilized to split the given SortedSet into a prefix/suffix pair at a stated position.
Method Definition: def splitAt(n: Int): (SortedSet[A], SortedSet[A]) Where, n is the position at which we need to split. Return Type: It returns a pair of TreeSets consisting of the first n elements of this SortedSet, and the other elements.
Example #1: Scala
// Scala program of splitAt() 
// method 
import scala.collection.mutable.SortedSet 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet(2, 4, 11, 31) 
        
        // Applying splitAt method 
        val result = s1.splitAt(2)
        
        // Display output
        println(result)
    } 
} 
Output:
(TreeSet(2, 4), TreeSet(11, 31))
Example #2: Scala
// Scala program of splitAt() 
// method 
import scala.collection.mutable.SortedSet 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet(1, 2, 3, 4) 
        
        // Applying splitAt method 
        val result = s1.splitAt(2)
        
        // Display output
        println(result)
    } 
} 
Output:
(TreeSet(1, 2), TreeSet(3, 4))

Similar Reads