The isEmpty() is utilized to check if the TreeSet is empty or not.
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the TreeSet is empty or else it returns false.
Example #1:
// Scala program of isEmpty() // method // Import TreeSet import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating TreeSet
val q 1 = TreeSet( 1 , 2 , 3 , 4 , 5 )
// Print the TreeSet
println(q 1 )
// Applying isEmpty method
val result = q 1 .isEmpty
// Displays output
print( "TreeSet is empty: " + result)
}
} |
Output:
TreeSet(1, 2, 3, 4, 5) TreeSet is empty: false
Example #2:
// Scala program of isEmpty() // method // Import TreeSet import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating TreeSet
val q 1 = TreeSet[Int]()
// Print the TreeSet
println(q 1 )
// Applying isEmpty method
val result = q 1 .isEmpty
// Displays output
print( "TreeSet is empty: " + result)
}
} |
Output:
TreeSet() TreeSet is empty: true