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

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

Scala Mutable SortedMap exists() 方法与示例

exists()方法用于检查给定谓词是否满足 SortedMap 的元素。

示例 #1:

// Scala program of exists()
// 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)
          
        // Applying exists method
        val result = m1.exists(x => x._1 == "for" && x._2 == 3)
          
        // Displays output
        println(result)
      
    }
}
输出:
true

因此,此处所述谓词对于第二个键值对为 true,因此返回 true。
示例 #2:

// Scala program of exists()
// 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)
          
        // Applying exists method
        val result = m1.exists(x => x._1 == "geeks" && x._2 == 3)
          
        // Displays output
        println(result)
      
    }
}
输出:
false