Scala Map iterator method with example
The iterator method is utilized to give an iterator.
Method Definition: def iterator: Iterator[(A, B)]
Return Type: It returns a non-empty iterator for non-empty map and returns an empty iterator for empty map.
Example #1:
// Scala program of iterator // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a map val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2) // Applying iterator method val result = m1.iterator // Displays output println(result) } } |
chevron_right
filter_none
Output:
non-empty iterator
Example #2:
// Scala program of iterator // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a map val m1 = Map() // Applying iterator method val result = m1.iterator // Displays output println(result) } } |
chevron_right
filter_none
Output:
empty iterator
Recommended Posts:
- Scala Iterator max() method with example
- Scala Iterator map() method with example
- Scala Iterator take() method with example
- Scala Iterator min() method with example
- Scala Iterator zip() method with example
- Scala Iterator seq() method with example
- Scala Iterator sum() method with example
- Scala Iterator next() method with example
- Scala List iterator() method with example
- Scala Iterator toSeq() method with example
- Scala Iterator toString() method with example
- Scala Iterator length() method with example
- Scala Iterator drop() method with example
- Scala Iterator indexWhere() method with example
- Scala Iterator hasDefiniteSize() 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 contribute@geeksforgeeks.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.



