Related Articles

Related Articles

Scala Iterator min() method with example
  • Last Updated : 26 Jun, 2019

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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
  
    }
}

chevron_right


Output:

11

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
  
    }
}

chevron_right


Output:

1.1



My Personal Notes arrow_drop_up
Recommended Articles
Page :