Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Scala BitSet ++[B](that: GenTraversableOnce[B]) 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 ++[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)



My Personal Notes arrow_drop_up
Recommended Articles
Page :