Open In App

Scala immutable TreeSet isEmpty() method

Last Updated : 19 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In Scala immutable TreeSet class 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.immutable._
  
// 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.immutable._
  
// 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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads