Open In App

Scala Mutable SortedSet size() method

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

Method Definition: def size: Int



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

Example #1:




// Scala program of size() 
// method 
import scala.collection.mutable.SortedSet
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet(2, 5
          
        // Applying size method 
        val result = s1.size
          
        // Display output
        println(result)
    

Output:

2

Example #2:




// Scala program of size() 
// method 
import scala.collection.mutable.SortedSet
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet(2, 10, 115, 96, 36, 47, 458, 21
          
        // Applying size method 
        val result = s1.size
          
        // Display output
        println(result)
    

Output:
8

Article Tags :