Scala immutable TreeSet last() method
In Scala immutable TreeSet class last() method is utilized to return the last element of the TreeSet.
Method Definition: def last: A
Return Type: It returns the last element of the TreeSet.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = TreeSet( 1 , 2 , 3 , 4 , 5 )
println(q 1 )
val result = q 1 .last
print( "Last element of the TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
Last element of the TreeSet: 5
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = TreeSet( "u" , "a" , "i" , "o" , "e" )
println(q 1 )
val result = q 1 .last
print( "Last element of the TreeSet: " + result)
}
}
|
Output:
TreeSet(a, e, i, o, u)
Last element of the TreeSet: u
Last Updated :
19 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...