Example
Empty the map by removing all items.
import java.util.HashMap;
public class Main {
public static void main(String[] args ) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities .put("England", "London");
capitalCities .put("Germany", "Berlin");
capitalCities .put("Norway", "Oslo");
capitalCities .put("USA", "Washington DC");
capitalCities .clear();
System.out .println(capitalCities );
}
}
|
Definition and Usage
The clear() method removes all entries from the map.
Syntax