Scala Map isEmpty() method with example
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 m 1 = Map( 3 - > "Beginner" , 1 - > "for" , 2 - > "cs" , 3 - > "Beginner" ) // Applying isEmpty method val result = m 1 .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 m 1 = Map() // Applying isEmpty method val result = m 1 .isEmpty // Displays output println(result) } } |
Output:
true
Contact Us