Scala Mutable SortedMap take() method with example
The take() method is utilized to select the first ‘n’ elements of the SortedMap.
Method Definition: def take(n: Int): SortedMap[A, B]
Return Type: It returns the first ‘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 .take( 2 )
println(result)
}
}
|
Output:
Map(2 -> cs, 3 -> geeks)
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 .take( 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...