当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala Iterator next()用法及代码示例


next()方法属于类AbstractIterator的Abstract Value Members。它在类Iterator中定义。它给出了所述迭代器的下一个元素,并推进了迭代器。

函数定义: def next():A

返回类型: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


相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Scala Iterator next() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。