Skip to content
Related Articles

Related Articles

Scala BitSet &(GenSet[]) 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 &~(GenSet[]) method is utilised compute the difference of this bitset and another bitset by performing a bitwise “and”.

Method Definition: def &(GenSet[])

Return Type: It returns a new bitset consisting of all elements that are that are both in this bitset.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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 = Set(1, 100, 55, 32, 23
  
        // Applying BitSet &(GenSet[]) function 
        val bs1 = b1 & (b2)
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

BitSet(1, 23)

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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 &(GenSet[]) function 
        val bs1 = b1 & Set(1, 100, 55, 32, 23
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

BitSet(1, 23)



My Personal Notes arrow_drop_up
Recommended Articles
Page :