Scala TreeSet max() method with example
Last Updated :
11 Nov, 2019
The max() method is utilized to return the largest method of the TreeSet.
Method Definition: def max: A
Return Type: It returns the largest element of the TreeSet.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = TreeSet( 1 , 2 , 3 , 4 , 5 )
println(q 1 )
val result = q 1 .max
print( "Largest element in the TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
Largest element in the TreeSet: 5
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = TreeSet( "u" , "a" , "i" , "o" , "e" )
println(q 1 )
val result = q 1 .max
print( "Largest element in the TreeSet: " + result)
}
}
|
Output:
TreeSet(a, e, i, o, u)
Largest element in the TreeSet: u
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...