Scala Iterator next() 方法与示例
next()方法属于 AbstractIterator 类的抽象值成员。它在Iterator类中定义。它给出了指定迭代器的下一个元素并推进迭代器。
Method Definition : def next(): A
Return Type :It returns the next element of the stated collection.
示例 #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)
}
}
输出:
5
8
示例 #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)
}
}
输出:
1.1
2.2