Scala Set head() method with example Improve Improve Like Article Like Save Share 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 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 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 Last Updated : 18 Oct, 2019 Like Article Save Article Previous Scala Set splitAt() method with example Next Scala Long +(x: Double) method Share your thoughts in the comments Add Your Comment Please Login to comment...