Skip to content
Related Articles

Related Articles

Improve Article
Scala Iterator product() method with example
  • Last Updated : 13 Aug, 2019

The product() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to Multiply all the elements of the stated collection.

Method Definition: val result = iter.product

Return Type: It returns the result obtained by multiplying all the elements of the stated iterator.

Example #1:




// Scala program of product()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(1, 2, 3, 4, 5, 6)
          
        // Applying product method 
        val result = iter.product
          
        // Displays output
        println(result)
      
    }
}
Output:
720

Example #2:




// Scala program of product()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(0, 1)
          
        // Applying product method 
        val result = iter.product
          
        // Displays output
        println(result)
      
    }
}
Output:
0



My Personal Notes arrow_drop_up
Recommended Articles
Page :