Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, October 29, 2015

Codecademy > Learn Java > Iterating over a HashMap Sample Solution


import java.util.HashMap;

public class RestaurantForEach {
public static void main(String[] args) {

HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();

restaurantMenu.put("Turkey Burger", 13);
restaurantMenu.put("Naan Pizza", 11);
restaurantMenu.put("Cranberry Kale Salad", 10);

System.out.println(restaurantMenu.size());

for (String item : restaurantMenu.keySet()) {

System.out.println("A " + item + " costs " + restaurantMenu.get(item) + " dollars.");

}

}
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts