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:
import scala.collection.immutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 5 , 1 , 2 , 3 , 4 )
val result = s 1 .head
println(result)
}
}
|
Example #2:
import scala.collection.immutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 41 , 16 , 22 , 3 , 51 )
val result = s 1 .head
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...