Scala Mutable SortedSet takeRight() method
Last Updated :
26 Mar, 2020
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.
Example #1:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 1 , 2 , 3 , 4 , 1 )
val result = s 1 .takeRight( 4 )
println(result)
}
}
|
Output:
TreeSet(1, 2, 3, 4)
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 41 , 12 , 23 , 43 )
val result = s 1 .takeRight( 3 )
println(result)
}
}
|
Output:
TreeSet(23, 41, 43)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...