📌  相关文章
📜  Scala Mutable SortedMap max() 方法与示例

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

Scala Mutable SortedMap max() 方法与示例

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

示例 #1:

// Scala program of max()
// method
import scala.collection.SortedMap
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("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
import scala.collection.SortedMap
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating SortedMap
        val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 6)
          
          
        // Applying max method 
        val result = m1.max
          
        // Displays output
        println(result)
    }
}
输出:
(geeks, 6)