Scala BitSet &~(GenSet[])方法及其示例
Scala BitSet是一组非负整数,表示为打包到64位字中的位的可变大小位数组。 &~(GenSet[])方法被用于计算此bitset与另一个bitset的差异,通过执行按位“与非”。
方法定义: def &~(GenSet[])
返回类型: 返回一个由所有不包含在给定bitset中的元素组成的新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(12, 41, 43, 72)
示例#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(12, 41, 43, 72)
更多Scala相关文章,请阅读:Scala 教程