Scala Iterator min() 方法与示例
min() 方法属于 AbstractIterator 类的具体值成员。它在IterableOnceOps类中定义。它用于找到最小的元素。
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.
示例 #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)
}
}
输出:
11
在这里,返回指定集合的最小元素。
示例 #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)
}
}
输出:
1.1