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
.
AbstractMap.isEmpty();
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 AbstractMapAbstractMap<String, String>abstractMap = new HashMap<String, String>();// Checking for any key-value pair in the MapSystem.out.println("Is the AbstractMap empty? "+ abstractMap.isEmpty());// Mapping string values to string keysabstractMap.put("One", "Shot");abstractMap.put("Of", "Java");abstractMap.put("Edpresso", "Yaaaayy");// Printing the AbstractMapSystem.out.println("The Mappings are: "+ abstractMap);// Checking for any key-value pair in the MapSystem.out.println("Is the AbstractMap empty? "+ abstractMap.isEmpty());}}