Open In App

Scala BitSet addString() method with example

Last Updated : 04 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The addString() method is utilised to append all elements of this traversable or iterator to a string builder.

Method Definition: def addString()

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

Example #1:




// 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
      
    


Output:

0123

Example #2:




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


Output:

112233


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads