方法一:使用Entry<KEY,VALUVE>
例如:
Map<String,Integer> items = cart.getCart();
Set<Entry<String,Integer>> entry = items.entrySet();
Iterator<Entry<String,Integer>> it = entry.iterator();
while (it.hasNext()) {
Entry<String,Integer> en = it.next();
out.println("商品名称:" + en.getKey() + "的数量为" + en.getValue() + "<br />");
}
方法二:使用keySet()
例如:
Map<String,Integer> items = cart.getCart();
Set<String> keys = items.keySet();
for (String k : keys) {
out.println("商品名称:" + k + "的数量为" + items.get(k)+ "<br />");
}