Scala TreeSet splitAt() method with example Last Updated : 11 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Scala // Scala program of splitAt() // method // Import TreeSet import scala.collection.mutable._ // 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) } } Output: TreeSet(1, 2, 3, 4, 5) (TreeSet(1, 2), TreeSet(3, 4, 5)) Example #2: Scala // Scala program of splitAt() // method // Import TreeSet import scala.collection.mutable._ // 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) } } Output: TreeSet(1, 2, 3, 4, 5) (TreeSet(1, 2, 3), TreeSet(4, 5)) Comment More infoAdvertise with us Next Article Scala TreeSet toMap() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala TreeSet take() method with example The take() method is utilized to return a TreeSet consisting of the first ânâ elements of the TreeSet. Method Definition: def take(n: Int): TreeSet[A] Return Type: It returns a TreeSet consisting of the first ânâ elements of the TreeSet. Example #1: Scala // Scala program of take() // method // Impo 1 min read Scala TreeSet toList() method with example The toList() method is utilized to return a list consisting of all the elements of the TreeSet. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toList() // method // Import TreeSet import scala 2 min read Scala Stack splitAt() method with example In Scala Stack class, the splitAt() method is utilized to split the given stack into a prefix/suffix pair of stacks at a stated position. Method Definition: def splitAt(n: Int): (Stack[A], Stack[A]) Return Type: It returns a pair of stacks consisting of the first n elements of this stack, and the ot 1 min read Scala TreeSet toMap() method with example The toMap() method is utilized to return a map consisting of all the elements of the TreeSet. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toMap() // method // Import TreeSet import sc 2 min read Scala TreeSet -() method with example In Scala TreeSet class, the -() method is utilized to remove an element from the given TreeSet. Method Definition: def -(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an element removed from the given TreeSet. Example #1: Scala // Scala program of -() // method // Import TreeSet im 1 min read 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 // Scala program of toSeq() // method // Import TreeSet import scala.colle 2 min read Like