Open In App

Scala BitSet &~() method with example

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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 compute the difference of this bitset and another bitset by performing a bitwise “and-not”.

Method Definition: def &~()

Return Type: It returns a new bitset consisting of all elements that are not contained in given 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(41, 12, 23, 43, 1, 72
        val b2: BitSet = BitSet(1, 100, 55, 32, 23
  
        // Applying BitSet &~() function 
        val bs1: BitSet = b1 &~ (b2)
          
        // Displays output 
        println(bs1
      
    


Output:

BitSet(12, 41, 43, 72)

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(41, 12, 23, 43, 1, 72
  
        // Applying BitSet &~() function 
        val bs1: BitSet = b1 &~ BitSet(1, 100, 5, 12, 23
          
        // Displays output 
        println(bs1
      
    


Output:

BitSet(41, 43, 72)


Last Updated : 04 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads