Scala Mutable SortedMap keys() method with example
The keys() method is utilized to give an iterator over all the keys of the SortedMap.
Method Definition: def keys: Iterable[A]
Return Type: It returns an iterator over all the keys of the SortedMap.
Example #1:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "geeks" - > 5 , "for" - > 3 , "cs" - > 2 )
val result = m 1 .keys
println(result)
}
}
|
Output:
Set(cs, for, geeks)
Example #2:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "geeks" - > 5 , "for" - > 3 , "geeks" - > 5 )
val result = m 1 .keys
println(result)
}
}
|
So, the identical keys are taken only once.
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...