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:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 50 , 60 , 11 , 90 , 21 )
val iter 1 = iter.min
println(iter 1 )
}
}
|
Here, the smallest element of the stated collection is returned.
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2.1 , 3.3 , 1.1 , 4.6 )
val iter 1 = iter.min
println(iter 1 )
}
}
|
Share your thoughts in the comments
Please Login to comment...