Scala BitSet addString(sb: mutable.StringBuilder, start, sep, end) method with example

Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The addString(sb: mutable.StringBuilder, start: String, sep: String, end: String) method is utilised to appends all elements of this bitset to a string builder using start, end, and separator strings.

Method Definition: def addString()

Return Type: It returns the string builder b to which elements were appended.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of Bitset addString
// 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
        val b = new StringBuilder()
  
  
        // Applying BitSet addString() function 
        val  bs1 = bitSet.addString(b)
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

0123

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of Bitset addString
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
  
        val bitSet: BitSet = BitSet(11, 22, 33, 44
        val b = new StringBuilder()
  
  
        // Applying BitSet addString() function 
        val  bs1 = bitSet.addString(b, "BitSet(", ", ", ")")
          
        // Displays output 
        println(bs1
      
    

chevron_right


Output:

BitSet(11, 22, 33, 44)



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.