当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala Iterator min()用法及代码示例


min()方法属于AbstractIterator类的具体值成员。它在IterableOnceOps类中定义。它用于查找最小的元素。

函数定义: 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.



返回类型: 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


相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Scala Iterator min() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。