Scala Mutable SortedMap takeRight() method with example
The takeRight() method is utilized to select the last ‘n’ elements of the SortedMap.
Method Definition: def takeRight(n: Int): SortedMap[A, B]
Return Type: It returns the last ‘n’ elements of the SortedMap.
Example #1:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 2 - > "cs" )
val result = m 1 .takeRight( 2 )
println(result)
}
}
|
Output:
Map(3 -> geeks, 4 -> for)
Example #2:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 2 - > "cs" )
val result = m 1 .takeRight( 4 )
println(result)
}
}
|
Output:
Map(2 -> cs, 3 -> geeks, 4 -> for)
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...