Scala Iterator next() method with example
Last Updated :
30 Jun, 2019
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:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 5 , 8 , 10 , 13 , 15 )
val result = iter.next
val res = iter.next
println(result)
println(res)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 1.1 , 2.2 )
val result = iter.next
val res = iter.next
println(result)
println(res)
}
}
|
Share your thoughts in the comments
Please Login to comment...