Scala Map max() 方法与示例
max()方法用于查找地图的最大元素。
Method Definition: def max: (A, B)
Return Type: It returns the largest element of the map.
示例 #1:
// Scala program of max()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2)
// Applying max method
val result = m1.max
// Displays output
println(result)
}
}
输出:
(geeks, 5)
示例 #2:
// Scala program of max()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map("geeks" -> 5, "for" -> 3, "geeks" -> 6)
// Applying max method
val result = m1.max
// Displays output
println(result)
}
}
输出:
(geeks, 6)