Skip to content
Related Articles

Related Articles

Scala Mutable SortedSet init() method
  • Last Updated : 26 Mar, 2020
GeeksforGeeks - Summer Carnival Banner

In Scala mutable collections, SortedSet init() method is utilized to find all the elements of the SortedSet except the last one.

Method Definition: def init: SortedSet[A]

Return Type: It returns all the elements of the SortedSet except the last one.

Example #1:




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



TreeSet(1, 2, 3, 4)

Example #2:




// Scala program of init() 
// method 
import scala.collection.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet(16, 22, 3, 41, 51
          
        // Applying init method 
        val result = s1.init
          
        // Display output
        println(result)
    
Output:
TreeSet(3, 16, 22, 41)

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 :