Skip to content
Related Articles

Related Articles

Scala BitSet count() 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 count() method is utilised to count the number of elements in the traversable or iterator

Method Definition: def count()

Return Type: It returns the count of elements

Example #1:




// Scala program of count() 
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating BitSet 
        val s1 = BitSet(1, 2, 3, 4, 5
          
        // Applying count method 
        val result = s1.count(z=>true
          
        // Displays output 
        println(result) 
      
    
Output:
5

Example #2:




// Scala program of count() 
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating BitSet 
        val s1 = BitSet(11, 22, 33
          
        // Applying count method 
        val result = s1.count(z=>true
          
        // Displays output 
        println(result) 
      
    
Output:
3



My Personal Notes arrow_drop_up
Recommended Articles
Page :