Skip to content
Related Articles

Related Articles

Scala Mutable SortedSet count() method
  • Last Updated : 26 Mar, 2020

In Scala mutable collections, count() method is utilized to count the number of elements in the SortedSet.

Method Definition: def count(p: (A) => Boolean): Int

Return Type: It returns the number of elements present in the SortedSet.

Example #1:




// Scala program of count()
// method
import scala.collection.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating SortedSets 
        val s1 = SortedSet(10, 22, 32, 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.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating SortedSets 
        val s1 = SortedSet(72, 666, 454
          
        // Applying count method 
        val result = s1.count(z=>true
          
        // Displays output 
        println(result) 
      
    
Output:
3

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :