JAVA 遍历HashMap

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值