Scala BitSet exists() 方法及示例

Scala BitSet exists() 方法及示例

Scala 的 Bitsets 是非负整数的集合,它们被表示为大小可变的位数组且打包成 64 位字。exists() 方法用于测试此可迭代集合的元素是否至少有一个满足谓词。

方法定义:def exists()

返回类型:如果此可迭代集合为空,则返回 false;否则返回 true。

示例 #1:

// Scala program of exists() 
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating BitSet 
        val s1 = BitSet(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.BitSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating BitSet 
        val s1 = BitSet(1, 2, 3, 4, 5) 
  
          
        // Applying exists method 
        val result = s1.exists(y => {y % 7 == 0})  
          
        // Displays output 
        println(result) 
      
    } 
} 
false

更多Scala相关文章,请阅读:Scala 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程