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:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 3 , 1 , 5 , 2 , 4 )
println(t 1 )
val result = t 1 .splitAt( 2 )
print(result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
(TreeSet(1, 2), TreeSet(3, 4, 5))
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 3 , 1 , 5 , 2 , 4 )
println(t 1 )
val result = t 1 .splitAt( 3 )
print(result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
(TreeSet(1, 2, 3), TreeSet(4, 5))
Last Updated :
19 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...