Using HashMaps in Java


HashMaps store items in “key/value” pairs, and you can access them by an index of another type.

Source Code

import java.util.HashMap; // import the HashMap class

HashMap capitalCities = new HashMap();
// Add keys and values (Country, City)
capitalCities.put("England", "London");
capitalCities.put("Germany", "Berlin");
capitalCities.put("Norway", "Oslo");
capitalCities.put("USA", "Washington DC");
System.out.println(capitalCities);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments