Scala SortedMap keys() method with example
Last Updated :
03 Nov, 2019
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.immutable.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.immutable.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.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...