The max() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the classes IterableOnceOps. It is utilized to find the largest element.
Method Definition : def max[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 largest element of the collection stated with respect to the ordering ord.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 22 , 36 , 66 , 19 , 21 )
val iter 1 = iter.max
println(iter 1 )
}
}
|
Therefore, the largest element of the collection stated is returned.
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2.2 , 3.6 , 6.6 , 9.9 , 2.1 )
val iter 1 = iter.max
println(iter 1 )
}
}
|