Scala Map min() 方法与示例
min()方法用于查找地图的最小元素。
Method Definition: def min: (A, B)
Return Type: It returns the smallest element of the map.
示例 #1:
// Scala program of min()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2)
// Applying min method
val result = m1.min
// Displays output
println(result)
}
}
输出:
(cs, 2)
正如我们在上面的示例中看到的那样, cs是地图中的最小元素。
示例 #2:
// Scala program of min()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map("geeks" -> 5, "for" -> 3, "for" -> 6)
// Applying min method
val result = m1.min
// Displays output
println(result)
}
}
输出:
(for, 6)