Scala BitSet apply() 方法与示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 +() 方法用于测试该集合中是否包含某个元素。
Method Definition: def apply()
Return Type: true if elem is contained in this set, false otherwise.
示例 #1:
// Scala program of apply()
// 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 apply method
val result = s1.apply(3)
// Displays output
println(result)
}
}
输出:
true
示例 #2:
// Scala program of apply()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(10, 20, 30, 40, 50, 70)
// Applying apply method
val result = s1.apply(60)
// Displays output
println(result)
}
}
输出:
false