Scala BitSet copyToArray() method with example

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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) 
          
        // Displays output 
        for(elem <- arr) 
        println(elem) 
      
    

chevron_right


Output:

1
2
3
0
0

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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, 55
          
        val arr: Array[Int] = Array(0, 0, 0, 0, 0
          
        // Applying copyToArray method 
        s1.copyToArray(arr) 
          
        // Displays output 
        for(elem <- arr) 
        println(elem) 
      
    

chevron_right


Output:

11
22
33
55
0



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.