In Scala mutable collections, takeRight() method is utilized to return a SortedSet consisting of last ‘n’ elements of the SortedSet.
Method Definition: def takeRight(n: Int):SortedSet[A]
Where ‘n’ is specifies the number of elements to select.
Return Type: It returns a SortedSet consisting of last ‘n’ elements of the SortedSet.
TreeSet(1, 2, 3, 4)
TreeSet(23, 41, 43)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.