Skip to content
Related Articles

Related Articles

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

In Scala mutable collections, last() method is utilized to return the last element of the SortedSet.

Method Definition: def last: A

Return Type: It returns the last element of the SortedSet.

Example #1:




// Scala program of last() 
// 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
          
        // Applying last method 
        val result = s1.last
          
        // Display output
        println(result)
    
Output:



4

Example #2:




// Scala program of last() 
// method 
import scala.collection.mutable.SortedSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
        // Creating a SortedSet 
        val s1 = SortedSet("geeks", "for", "geeks", "classes"
          
        // Applying last method 
        val result = s1.last
          
        // Display output
        println(result)
    
Output:
geeks

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 :