Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Scala BitSet -() 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 -() method is utilised to create new set with a given element removed from this set.

Method Definition: def -(elem)

Return Type: It returns new set that contains all elements of this set but that does not contain elem

Example #1:




// Scala program of Bitset -
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
  
        val bitSet: BitSet = BitSet(0, 1, 2, 3
        println(s"Elements in Bitset are = $bitSet"
  
        // Applying BitSet -() function 
        val bs1: BitSet = bitSet - 0
          
        // Displays output 
        println(bs1
      
    
Output:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(1, 2, 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 bitSet: BitSet = BitSet(0, 1, 2, 3
        println(s"Elements in Bitset are = $bitSet"
  
        // Applying BitSet -() function 
        val bs1: BitSet = bitSet - (1, 3)
          
        // Displays output 
        println(bs1
      
    
Output:
Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 2)



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!