Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is AbstractMap isEmpty in Java?

Divine Odazie

AbstractMap.isEmpty() is a method of the Java AbstractMap class. We use it to check if an AbstractMap contains no key-value pairs. If there is no key-value pair in the AbstractMap, the function returns true; otherwise, it returns​ false.

Syntax

AbstractMap.isEmpty();

Code

We can represent the illustration shown above in the code snippet below. Let’s run the code to test it.

import java.util.*;

class AbstractMapDemo {
    public static void main(String[] args)
    {
  
        // Creating an AbstractMap
        AbstractMap<String, String>
            abstractMap = new HashMap<String, String>();

        // Checking for any key-value pair in the Map
        System.out.println("Is the AbstractMap empty? "
                           + abstractMap.isEmpty());
  

        // Mapping string values to string keys
        abstractMap.put("One", "Shot");
        abstractMap.put("Of", "Java");
        abstractMap.put("Edpresso", "Yaaaayy");
    
  
        // Printing the AbstractMap
        System.out.println("The Mappings are: "
                           + abstractMap);
  
        // Checking for any key-value pair in the Map
        System.out.println("Is the AbstractMap empty? "
                           + abstractMap.isEmpty());
    }
}

RELATED TAGS

java
communitycreator
RELATED COURSES

View all Courses

Keep Exploring