Skip to content
Related Articles

Related Articles

Improve Article
Scala TreeSet isEmpty() method with example
  • Last Updated : 11 Nov, 2019

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 q1 = TreeSet(1, 2, 3, 4, 5)  
            
        // Print the TreeSet 
        println(q1
          
        // Applying isEmpty method  
        val result = q1.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 q1 = TreeSet[Int]()  
            
        // Print the TreeSet 
        println(q1
          
        // Applying isEmpty method  
        val result = q1.isEmpty  
            
        // Displays output  
        print("TreeSet is empty: " + result) 
          
    
Output:
TreeSet()
TreeSet is empty: true



My Personal Notes arrow_drop_up
Recommended Articles
Page :