Scala BitSet &(GenSet[]) 方法示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 &~(GenSet[]) 方法用于通过执行按位“与”来计算该位集与另一个位集的差异。
Method Definition: def &(GenSet[])
Return Type: It returns a new bitset consisting of all elements that are that are both in this bitset.
示例 #1:
// Scala program of Bitset &
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val b1: BitSet = BitSet(41, 12, 23, 43, 1, 72)
val b2 = Set(1, 100, 55, 32, 23)
// Applying BitSet &(GenSet[]) function
val bs1 = b1 & (b2)
// Displays output
println(bs1)
}
}
输出:
BitSet(1, 23)
示例 #2:
// Scala program of Bitset &
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val b1: BitSet = BitSet(41, 12, 23, 43, 1, 72)
// Applying BitSet &(GenSet[]) function
val bs1 = b1 & Set(1, 100, 55, 32, 23)
// Displays output
println(bs1)
}
}
输出:
BitSet(1, 23)