Open In App

Scala Iterator product() method with example

Last Updated : 13 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads