To remove an item, use the remove() method and refer to the key:

Example

capitalCities.remove("England");
 

To remove all items, use the clear() method:

Example

capitalCities.clear();



Practice Excercise Practice now