📜  Scala Map max() 方法与示例

📅  最后修改于: 2022-05-13 01:54:48.077000             🧑  作者: Mango

Scala Map max() 方法与示例

max()方法用于查找地图的最大元素。

示例 #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)