Skip to content
Related Articles

Related Articles

Scala SortedSet head() method with example
  • Last Updated : 03 Nov, 2019

The head() method is utilized to display the first element of the SortedSet.

Method Definition: def head: A

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

Example #1:




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

Example #2:




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



My Personal Notes arrow_drop_up
Recommended Articles
Page :