Open In App

Scala Iterator product() method with example

Last Updated : 13 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
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
// 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
// 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

Article Tags :

Similar Reads