你的map中key的类型是string吗?
解决方案 »
- flex4+blazeds+spring+hibernate集成错误
- Struts2 Push Tag 引发的问题
- 请教这个xml文件的具体解析方法
- 关于延迟加载,立即加载的问题
- 利用spring的配置文件得到一个类对象,怎么它就不能被rmi方法注册所调用呢?
- hibernate的问题,大家帮我看看可能是什么错误,给我定个方向!
- tomcat 启动时报错:don't found java.library.path
- AXIS服务器端handlers如何得到客户端传过来的信息
- JDBC连接mySQL数据库报错“java.lang.ClassNotFoundException: com.mysql.jdbc.Driver”,求助!!!
- 老手们,小弟求一个下载tomcat快点的地址!
- rs.getString怎么获取a表的age字段?
- 急,有关hibernate中session的flush()的错误,本人菜鸟
map.put(Integer.toString(i),new Integer(this.Free(plans[i], month, freeExtraTime)));
对HashMap不熟悉,没注意到这个问题。
程序也修改了一下。
调试的时候还发现,如果直接从map中remove,会报错。
所以,要用iter.remove(); public int cheapestValue(HashMap map)throws Exception{
Iterator iter = map.keySet().iterator();
String tmpKey = "0";
Integer tmpV = (Integer)map.get("0");
int tmpValue = tmpV.intValue(); while(iter.hasNext()){
String key = (String)iter.next();
Integer V = (Integer)map.get(key);
int Value = V.intValue();
if(Value < tmpValue){
tmpValue = Value;
tmpKey = key;
iter.remove();
}else{
iter.remove();
}
}
return Integer.parseInt(tmpKey);
}