Scala BitSet copyToArray() method with example
Last Updated :
04 May, 2020
Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The +() method is utilised to copy the elements of this bitset to an array.
Method Definition: def copyToArray()
Return Type: copy of bitset array
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val s 1 = BitSet( 1 , 2 , 3 )
val arr : Array[Int] = Array( 0 , 0 , 0 , 0 , 0 )
s 1 .copyToArray(arr)
for (elem < - arr)
println(elem)
}
}
|
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val s 1 = BitSet( 11 , 22 , 33 , 55 )
val arr : Array[Int] = Array( 0 , 0 , 0 , 0 , 0 )
s 1 .copyToArray(arr)
for (elem < - arr)
println(elem)
}
}
|
Share your thoughts in the comments
Please Login to comment...