HashMap需要获取所有值

时间:2015-02-10 19:17:35

标签: loops session hashmap

我需要从HashMap中凝胶化所有值,但我总是得到第一行值。

这是我的循环代码。

   Map<String, String> list1 = (Map<String,String>)session.getAttribute("cart");
   Collection c = list1.values();
   Iterator itr = c.iterator();
   while (itr.hasNext()) {
     String kiekis = itr.next().toString();
    String id = itr.next().toString();
    } 

1 个答案:

答案 0 :(得分:0)

使用entryset,例如

for(Map<String,String> map : list1){ 
    map.getKey(); ///Key
    map.getValue(); // value
}