Scala BitSet -() 方法示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 -() 方法用于创建新集合,并从该集合中删除给定元素。
Method Definition: def -(elem)
Return Type: It returns new set that contains all elements of this set but that does not contain elem
示例 #1:
// Scala program of Bitset -
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val bitSet: BitSet = BitSet(0, 1, 2, 3)
println(s"Elements in Bitset are = $bitSet")
// Applying BitSet -() function
val bs1: BitSet = bitSet - 0
// Displays output
println(bs1)
}
}
输出:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(1, 2, 3)
示例 #2:
// Scala program of Bitset -
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val bitSet: BitSet = BitSet(0, 1, 2, 3 )
println(s"Elements in Bitset are = $bitSet")
// Applying BitSet -() function
val bs1: BitSet = bitSet - (1, 3)
// Displays output
println(bs1)
}
}
输出:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 2)