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
- How to Reverse keys and values in Scala Map
- Scala SortedMap keys() method with example
- Scala Mutable SortedMap keys() method with example
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala | Either
- Set in Scala | Set-2
- Scala Map
- Set in Scala | Set-1
- Scala this keyword
- BitSet in Scala
- TreeSet in Scala
- Scala map contains() method with example
- Scala Int >=(x: Int) method with example
- Scala Int self() method with example
- Scala | Value Classes
- Scala Int to(end: Int) method with example
- Scala Int ^(x: Int) method with example
- Scala Int -(x: Int) method with example
- Scala Int | (x: Int) method with example
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.