Scala BitSet count() 方法示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 count() 方法用于计算可遍历或迭代器中的元素个数
Method Definition: def count()
Return Type: It returns the count of elements
示例 #1:
// Scala program of count()
// 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 count method
val result = s1.count(z=>true)
// Displays output
println(result)
}
}
输出:
5
示例 #2:
// Scala program of count()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(11, 22, 33)
// Applying count method
val result = s1.count(z=>true)
// Displays output
println(result)
}
}
输出:
3