Open In App

Scala Iterator min() method with example

Last Updated : 26 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The min() method belongs to the concrete value members of the class AbstractIterator. It is defined in the classes IterableOnceOps. It is utilized to find the smallest element.

Method Definition : def min[B >: A](implicit ord: math.Ordering[B]): A

Where, B is the type over which the ordering is defined and ord is an ordering to be used for comparing elements.

Return Type : It returns the smallest element of the collection stated with respect to the ordering ord.

Example #1:




// Scala program of min()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Declaring an iterator
        val iter = Iterator(50, 60, 11, 90, 21)
          
        // Applying min method
        val iter1 = iter.min
          
        // Displays output
        println(iter1)
  
    }
}


Output:

11

Here, the smallest element of the stated collection is returned.
Example #2:




// Scala program of min()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Declaring an iterator
        val iter = Iterator(2.1, 3.3, 1.1, 4.6)
          
        // Applying min method
        val iter1 = iter.min
          
        // Displays output
        println(iter1)
  
    }
}


Output:

1.1


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads