点击运行
import java.util.*; public class IterationExample3 { public static void main(String[] arg) { Map
map = new HashMap
(); map.put("Cookies", 90.87f); map.put("Dry Fruits", 434.23f); map.put("Oats", 220.00f); map.put("Chocolate", 70.89f); for (Map.Entry
entry : map.entrySet()) //使用 map.entrySet() 遍历 { // 返回响应的 key 和 value System.out.println("Item: " + entry.getKey() + ", Price: " + entry.getValue()); } } }
运行结果 :
正在执行...