Scala SortedSet splitAt() method with example
Last Updated :
03 Nov, 2019
The 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:
import scala.collection.immutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 2 , 4 , 11 , 31 )
val result = s 1 .splitAt( 2 )
println(result)
}
}
|
Output:
(TreeSet(2, 4), TreeSet(12, 31))
Example #2:
import scala.collection.immutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 1 , 2 , 3 , 4 )
val result = s 1 .splitAt( 2 )
println(result)
}
}
|
Output:
(TreeSet(1, 2), TreeSet(3, 4))
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...