Scala immutable TreeSet takeRight() method Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In Scala immutable TreeSet class the takeRight() method is utilised to return a TreeSet consisting of the last ānā elements of the TreeSet. Method Definition: def takeRight(n: Int):TreeSet[A] Return Type: It returns a TreeSet consisting of the last ānā elements of the TreeSet. Example #1: Scala // Scala program of takeRight() // 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 takeRight method val result = t1.takeRight(2) // Displays output print("TreeSet containing last two elements: " + result) } } Output: TreeSet(1, 2, 3, 4, 5) TreeSet containing last two elements: TreeSet(4, 5) Example #2: Scala // Scala program of takeRight() // 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 takeRight method val result = t1.takeRight(3) // Displays output print("TreeSet containing last three elements: " + result) } } Output: TreeSet(1, 2, 3, 4, 5) TreeSet containing last three elements: TreeSet(3, 4, 5) Comment More infoAdvertise with us Next Article Scala immutable TreeSet toList() method S Shivam_k Follow Improve Article Tags : Scala Scala immutable-TreeSet Similar Reads Scala immutable TreeSet take() method In Scala immutable TreeSet class 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 pr 1 min read Scala immutable TreeSet toString() method In Scala immutable TreeSet class the toString() method is utilised to return a string representation of the TreeSet object. Method Definition: def toString(): String Return Type: It returns a string representation of the TreeSet object. Example #1: Scala // Scala program of toString() // method // I 2 min read Scala immutable TreeSet toList() method In Scala immutable TreeSet class the toList() method is utilised 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() // meth 2 min read 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 1 min read Scala immutable TreeSet toMap() method In Scala immutable TreeSet class the toMap() method is utilised 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() // m 2 min read Scala immutable TreeSet toSeq() method In Scala immutable TreeSet class the toSeq() method is utilised 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 // 2 min read Like