Scala BitSet +() 方法示例
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 +() 方法用于创建带有附加元素的新集合,除非该元素已经存在。
Method Definition: def +()
Return Type: It returns a new set that contains all elements of this set.
示例 #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 + 10 + 11
// Displays output
println(bs1)
}
}
输出:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 1, 2, 3, 10, 11)
示例 #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 + 2 + 3
// Displays output
println(bs1)
}
}
输出:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 1, 2, 3)