📜  Scala Iterator zip() 方法与示例

📅  最后修改于: 2022-05-13 01:54:41.205000             🧑  作者: Mango

Scala Iterator zip() 方法与示例

zip()方法属于抽象迭代器类的具体值成员。它在迭代器类中定义。

示例 #1:

// Scala program of zip()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating the first Iterator 
        val iter = Iterator(1, 2, 3, 4, 5, 6)
          
        // Creating the second iterator
        val iter1 = Iterator(7, 8, 9, 10)
          
        // Applying zip method 
        val result = iter.zip(iter1)
          
        // Displays output
        println(result)
      
    }
}
输出:
non-empty iterator

示例 #2:

// Scala program of zip()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating the first Iterator 
        val iter = Iterator()
          
        // Creating the second iterator
        val iter1 = Iterator(0, 0, 0, 0)
          
        // Applying zip method 
        val result = iter.zip(iter1)
          
        // Displays output
        println(result)
      
    }
}
输出:
empty iterator