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