Map hiddenMap = new HashMap(); //获取Map的值 hiddenMap = (HashMap)sessionMap.get(Constants.hiddenMap); Set hiddenSet = hiddenMap.entrySet(); Iterator hiddenIterator = hiddenSet.iterator(); while(hiddenIterator.hasNext()){ Map.Entry<String,String> hiddenMapEntry = (Map.Entry<String,String>)hiddenIterator.next(); PutParam putparam = new PutParam(); String key = hiddenMapEntry.getKey(); putparam.setParam(key); String value = hiddenMapEntry.getValue(); value = BanausicMethod.transcode_yitai(value); putparam.setValue(hiddenMapEntry.getValue()); finalPostList.add(putparam); }
import java.util.Set;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
再贴个简单一点的:
Map<String,Double> pimap = bean.getPriceindexMap(); Set piset = pimap.entrySet(); Iterator piIterator = piset.iterator(); while(piIterator.hasNext()){ Map.Entry<String,Double> hiddenMapEntry = (Map.Entry<String,Double>)piIterator.next(); String key = hiddenMapEntry.getKey(); int year = Integer.parseInt(key.substring(0,4)); int month = Integer.parseInt(key.substring(4, 6)); series.add(new Month(month,year),hiddenMapEntry.getValue()); }
================
上面是程序中曾经用过的一段遍历HashMap的代码,
网上有一篇比较详细的说明,有兴趣的可以看看:
Java中Map的使用
http://blog.csdn.net/tomholmes7/archive/2008/07/16/2663379.aspx