读书人

求教一个强制转换的有关问题!

发布时间: 2011-11-23 23:51:20 作者: rapoo

求教一个强制转换的问题!!
String toLink = request.getParameter( "toLink ");
HashMap hm = new HashMap();
int count = 0;
if (application.getAttribute( "links ") != null) {
hm = new HashMap((HashMap) application.getAttribute( "links "));
if(hm.get(toLink)!=null){
count = Integer.parseInt(hm.get(toLink).toString());
}
}
hm.put(toLink, new Integer(count + 1));
application.setAttribute( "links ", hm);
response.sendRedirect(toLink);
.
.
.
.
HashMap hm = new HashMap((HashMap) application.getAttribute( "links "));
Integer[] o = (Integer[]) hm.values().toArray();
此时出现异常:ClassCastException

请问如何能解决呢?!!
我的目的是转成: Integer[] 或 int[];


[解决办法]
Integer[] o = new Integer[hm.size()];
hm.values().toArray(o);

读书人网 >Java Web开发

热点推荐