带有示例的 Scala BitSet -(elems: Int*) 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。使用 -(elems: Int*) 方法需要删除两个或更多元素。
Method Definition: def +()
Return Type: a new collection that contains all elements except one less occurrence of each of the given elements.
示例 #1:
// Scala program of Bitset -
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val b2: Set[Int] = BitSet(5, 6, 7, 55, 56, 57) - 55 - 56
// Displays output
println(b2)
}
}
输出:
BitSet(5, 6, 7, 57)
示例 #2:
// Scala program of Bitset -
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val b2: Set[Int] = BitSet(5, 6, 7) - 5 - 6 - 0
// Displays output
println(b2)
}
}
输出:
BitSet(7)