Scala BitSet –() 方法示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 –() 方法用于通过删除另一个集合的所有元素从该集合创建一个新集合。
Method Definition: def –()
Return Type: It returns a new collection that contains all elements of the current collection except elems.
示例 #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(0, 1, 2, 3, 4, 5)
val b2: BitSet = BitSet(4, 5)
// Applying BitSet --() function
val bs1: BitSet = b1 -- b2
// Displays output
println(bs1)
}
}
输出:
BitSet(0, 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 b1: BitSet = BitSet(0, 1, 2, 3, 15, 16)
val b2: BitSet = BitSet(15, 16, 0 )
// Applying BitSet --() function
val bs1: BitSet = b1 -- b2
// Displays output
println(bs1)
}
}
输出:
BitSet(1, 2, 3)