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

Last Updated : 4 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: TraversableOnce[B]) method is utilised create a collection containing the elements from the left hand operand followed by the elements from the right hand operand. Method Definition: def ++:[B](that: TraversableOnce[B]) Return Type: It returns a new bitset which contains all elements of this bitset followed by all elements of that. Example #1: Scala
// Scala program of Bitset ++
// method 
import scala.collection.immutable.BitSet 
import scala.collection.mutable.LinkedList 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 

        val b1 = BitSet(0, 1, 2, 3) 
        val b2 = LinkedList(100)

        // Applying BitSet ++() function 
        val bs1 = b1 ++: b2
        
        // Displays output 
        println(bs1) 
    
    } 
} 
Output:
LinkedList(0, 1, 2, 3, 100)
Example #2: Scala
// Scala program of Bitset ++
// method 
import scala.collection.immutable.BitSet 
import scala.collection.mutable.LinkedList 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 

        val b1 = BitSet(11, 22, 33) 
        val b2 = LinkedList("A", "B")

        // Applying BitSet ++() function 
        val bs1 = b1 ++: b2
        
        // Displays output 
        println(bs1) 
    
    } 
} 
Output:
LinkedList(0, 1, 2, 3, A, B)
Comment

Explore