In order to get all the keys from a Scala map, we need to use either keySet method (to get all the keys as a set) or we can use keys method and if you want to get the keys as an iterator, you need to use keysIterator method. Now, lets check some examples.
Set(3, 4, 2)
Here, keySet method is utilized.
Set(3, 4, 2)
Here, keys method is utilized.
Here, keysIterator method is utilized.
- Scala Map keys() method with example
- Scala SortedMap keys() method with example
- How to Reverse keys and values in Scala Map
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala | Either
- Scala Map
- Set in Scala | Set-2
- Set in Scala | Set-1
- Scala | Trait App
- Queue in Scala
- Scala Set -() method with example
- Scala Set &~() method with example
- Scala Set contains() method with example
- Scala Set ++() method with example
- How to sort a Scala Map by key
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.