Scala Iterator next() method with example
The next() method belongs to the Abstract Value Members of the class AbstractIterator. It is defined in the class Iterator. It gives the next element of the stated iterator and advance the iterator.
Method Definition : def next(): A
Return Type :It returns the next element of the stated collection.
Example #1:
// Scala program of next() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an Iterator val iter = Iterator(5, 8, 10, 13, 15) // Applying next method val result = iter.next // Applying next method // again val res = iter.next // Displays output println(result) println(res) } } |
chevron_right
filter_none
Output:
5 8
Example #2:
// Scala program of next() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an Iterator val iter = Iterator(1.1, 2.2) // Applying next method val result = iter.next // Applying next method // again val res = iter.next // Displays output println(result) println(res) } } |
chevron_right
filter_none
Output:
1.1 2.2
Recommended Posts:
- Scala Map iterator method with example
- Scala Iterator sum() method with example
- Scala Iterator seq() method with example
- Scala Iterator map() method with example
- Scala Iterator min() method with example
- Scala Iterator take() method with example
- Scala Iterator max() method with example
- Scala Iterator zip() method with example
- Scala Iterator toList() method with example
- Scala Iterator toBuffer() method with example
- Scala Iterator toIterable() method with example
- Scala Iterator sameElements() method with example
- Scala Iterator isTraversableAgain() method with example
- Scala Iterator indexOf() method with example
- Scala Iterator slice() 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.


