Scala Mutable SortedMap max() 方法与示例
max()方法用于查找 SortedMap 的最大元素。
Method Definition: def max: (A, B)
Return Type: It returns the largest element of the 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)