The Wayback Machine - https://web.archive.org/web/20220919225240/https://www.geeksforgeeks.org/scala-map-isempty-method-with-example/
Skip to content
Related Articles

Related Articles

Scala Map isEmpty() method with example

View Discussion
Improve Article
Save Article
  • Last Updated : 13 Aug, 2019
View Discussion
Improve Article
Save Article

The isEmpty() method is utilized to check if the given map is empty or not.

Method Definition: def isEmpty: Boolean

Return Type: It returns true if the stated map is empty else returns false.

Example #1:




// Scala program of isEmpty()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating map
        val m1 = Map(3 -> "geeks", 1 -> "for", 2 -> "cs", 3 -> "geeks")
          
        // Applying isEmpty method 
        val result = m1.isEmpty
          
        // Displays output
        println(result)
    }
}

Output:

false

Example #2:




// Scala program of isEmpty()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating map
        val m1 = Map()
          
        // Applying isEmpty method 
        val result = m1.isEmpty
          
        // Displays output
        println(result)
    }
}

Output:

true

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!