Scala BitSet copyToArray(xs, start, len) 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 +() 方法用于将此位集的元素复制到数组中。
Method Definition: def copyToArray()
Return Type: copy of bitset array
示例 #1:
// Scala program of copyToArray()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(1, 2, 3)
val arr: Array[Int] = Array(0, 0, 0, 0, 0)
// Applying copyToArray method
s1.copyToArray(arr, 1, 2)
// Displays output
for(elem <- arr)
println(elem)
}
}
输出:
0
1
2
0
0
示例 #2:
// Scala program of copyToArray()
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating BitSet
val s1 = BitSet(11, 22, 33)
val arr: Array[Int] = Array(0, 0, 0, 0, 0, 0)
// Applying copyToArray method
s1.copyToArray(arr, 2, 3)
// Displays output
for(elem <- arr)
println(elem)
}
}
输出:
0
0
11
22
33
0