Open In App

Scala SortedSet last() method with example

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

Next Article
Article Tags :

Similar Reads