Scala immutable TreeSet size() method
Last Updated :
19 Apr, 2020
In Scala immutable TreeSet class the size() method is utilised to return the number of elements present in the TrreSet.
Method Definition: def size: Int
Return Type: It returns the number of elements present in the TreeSet.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 3 , 1 , 5 , 2 , 4 )
println(t 1 )
val result = t 1 .size
print( "Size of the TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
Size of the TreeSet: 5
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 3 , 1 , 5 , 2 , 4 , 10 , 6 , 9 , 7 , 8 )
println(t 1 )
val result = t 1 .size
print( "Size of the TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Size of the TreeSet: 10
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...