Open In App

Scala BitSet ++[B](that: GenTraversableOnce[B]) method with example

Last Updated : 04 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The ++[B](that: GenTraversableOnce[B])
method is utilised create a bitset containing the elements from the left hand operand followed by the elements from the right hand operand.

Method Definition: def ++[B](that: GenTraversableOnce[B])

Return Type: It returns a new bitset which contains all elements of this bitset.

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 = List("a", "B"
  
        // Applying BitSet ++() function 
        val bs1 = b1 ++ b2
          
        // Displays output 
        println(bs1
      
    


Output:

Set(0, 1, a, 2, B, 3)

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 = List("A"
  
        // Applying BitSet ++() function 
        val bs1 = b1 ++ b2
          
        // Displays output 
        println(bs1
      
    


Output:

Set(0, 1, A, 2, 3)


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads