📜  Scala SortedSet exists() 方法示例

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

Scala SortedSet exists() 方法示例

exists()方法用于测试谓词是否适用于 SortedSet 的某些元素。

示例 #1:

// Scala program of exists() 
// method 
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a list 
        val s1 = SortedSet(1, 2, 3, 4, 5) 
          
        // Applying exists method 
        val result = s1.exists(y => {y % 3 == 0}) 
          
        // Displays output 
        println(result) 
          
    } 
} 
输出:
true

示例 #2:

// Scala program of exists() 
// method 
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a list 
        val s1 = SortedSet(1, 2, 3, 4, 5) 
          
        // Applying exists method 
        val result = s1.exists(y => {y % 7 == 0}) 
          
        // Displays output 
        println(result) 
          
    } 
} 
输出:
false