Example
Verify if a map contains no key-value mappings.
import java.util.HashMap;
public class Main {
public static void main(String[] args ) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
System.out .println(capitalCities .isEmpty());
capitalCities .put("England", "London");
capitalCities .put("Germany", "Berlin");
capitalCities .put("Norway", "Oslo");
capitalCities .put("USA", "Washington DC");
System.out .println(capitalCities .isEmpty());
}
}
|
Definition and Usage
The isEmpty() method returns true if the map contains no entries, and false otherwise.
Syntax
Technical Details
Returns:
|
It returns true if the map has no entries, and false otherwise.
|