Scala BitSet count() 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 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

5

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

3



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.