import java.util.Map; import java.util.HashMap; /** * A demo of using Maps in Java. */ public class MapExample { public static void main(String[] args) { // generics: specify types of keys and values Map citySizes = new HashMap(); citySizes.put("Portland", 65000); citySizes.put("Lewiston", 35000); citySizes.put("Brunswick", 20000); int lewistonPop = citySizes.get("Lewiston"); // loop over keys using for-each style loop for (String city : citySizes.keySet()) { // get the associated value int pop = citySizes.get(city); System.out.println("city " + city + " has population of " + pop); } } }