Skip to content
Related Articles

Related Articles

Scala BitSet +(elems: Int*) 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 +(elems: Int*) method is utilised create a new set with additional elements, omitting duplicates.

Method Definition: def +()

Return Type: It returns a new set omitting duplicates.

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 b2: Set[Int] = BitSet(5, 6, 7) + 55+56 
  
  
        // Displays output 
        println(b2
      
    

chevron_right


Output:

BitSet(5, 6, 7, 55, 56)

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 b2: Set[Int] = BitSet(5, 6, 7) + 5+6+0
  
  
        // Displays output 
        println(b2
      
    

chevron_right


Output:

BitSet(0, 5, 6, 7)



My Personal Notes arrow_drop_up
Recommended Articles
Page :