Skip to content
Related Articles

Related Articles

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 create a new set with an additional element, unless the element is already present.

Method Definition: def +()

Return Type: It returns a new set that contains all elements of this set.

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 bitSet: BitSet = BitSet(0, 1, 2, 3
        println(s"Elements in Bitset are = $bitSet"
  
        // Applying BitSet +() function 
        val bs1: BitSet = bitSet + 10 + 11
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 1, 2, 3, 10, 11)

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 bitSet: BitSet = BitSet(0, 1, 2, 3
        println(s"Elements in Bitset are = $bitSet"
  
        // Applying BitSet +() function 
        val bs1: BitSet = bitSet + 1 + 2 + 3
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

Elements in Bitset are = BitSet(0, 1, 2, 3)
BitSet(0, 1, 2, 3)



My Personal Notes arrow_drop_up
Recommended Articles
Page :