Open In App

Scala Set head() method with example

Last Updated : 18 Oct, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The head() method is utilized to display the first element of the set.
Method Definition: def head: A Return Type: It returns the first element of the set.
Example #1: Scala
// Scala program of head() 
// method 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a set 
        val s1 = Set(5, 1, 2, 3, 4) 
        
        // Applying head method 
        val result = s1.head
        
        // Display output
        println(result)
    } 
} 
Output:
5
Example #2: Scala
// Scala program of head() 
// method 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a set 
        val s1 = Set(41, 16, 22, 3, 51) 
        
        // Applying head method 
        val result = s1.head
        
        // Display output
        println(result)
    } 
} 
Output:
41

Next Article

Similar Reads