Open In App

Scala SortedSet count() method with example

Last Updated : 02 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The 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
// Scala program of count()
// method
import scala.collection.immutable.SortedSet 

// Creating object 
object GfG 
{ 

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

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
    
        // Creating SortedSets 
        val s1 = SortedSet(7, 6, 4) 
        
        // Applying count method 
        val result = s1.count(z=>true) 
        
        // Displays output 
        println(result) 
    
    } 
} 
Output:
3

Next Article
Article Tags :

Similar Reads