The Wayback Machine - https://web.archive.org/web/20211017185222/https://www.geeksforgeeks.org/scala-bitset-method-with-example-6/
Skip to content
Related Articles

Related Articles

Improve Article

Scala BitSet ++() 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 create a new set by adding all elements contained in another collection to this set, omitting duplicates.

Method Definition: def ++()

Return Type: It returns a new set with the given elements added,

Example #1:




// Scala program of Bitset ++
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
  
        val b1: BitSet = BitSet(0, 1, 2, 3) 
        val b2: BitSet = BitSet(4, 5, 6, 7) 
  
        // Applying BitSet ++() function 
        val bs1: BitSet = b1 ++ b2
          
        // Displays output 
        println(bs1) 
      
    } 
} 
Output:
BitSet(0, 1, 2, 3, 4, 5, 6, 7)

Example #2:




// Scala program of Bitset ++
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
  
        val b1: BitSet = BitSet(0, 1, 2, 3 ) 
        val b2: BitSet = BitSet(15, 16, 17 ) 
  
        // Applying BitSet ++() function 
        val bs1: BitSet = b1 ++ b2
          
        // Displays output 
        println(bs1) 
      
    } 
} 
Output:
BitSet(0, 1, 2, 3, 15, 16, 17)



My Personal Notes arrow_drop_up
Recommended Articles
Page :