Scala Set head() method with example
Last Updated :
18 Oct, 2019
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:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 5 , 1 , 2 , 3 , 4 )
val result = s 1 .head
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 41 , 16 , 22 , 3 , 51 )
val result = s 1 .head
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...