📜  Scala SortedSet contains() 方法与示例

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

Scala SortedSet contains() 方法与示例

contains() 方法用于检查元素是否存在于非排序集中。

示例 #1:

// Scala program of contains() 
// method 
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet(41, 12, 23, 43, 1, 72) 
          
        // Applying contains() method 
        val result = s1.contains(1)
              
        // Display output
        print(result)   
          
    } 
} 
输出:
true

示例 #2:

// Scala program of contains() 
// method 
import scala.collection.immutable.SortedSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet(41, 12, 23, 43, 1, 72) 
          
        // Applying contains() method 
        val result = s1.contains(10)
              
        // Display output
        print(result)   
          
    } 
} 
输出:
false