读书人

:关于HashMap get()返回为空

发布时间: 2012-01-16 23:36:51 作者: rapoo

求助:关于HashMap get()返回为空
代码是:
Iterator <Map.Entry <PCNode,ArrayList <PCEdge> > > it=arcsMap.entrySet().iterator();
while(it.hasNext()){
Map.Entry <PCNode,ArrayList <PCEdge> > p=it.next();
if(p.getKey().hashCode()==list.get(0).hashCode())
System.out.println(arcsMap.get(list.get(0))+p.getValue().toString());
}
输出结果是:
null[proteinconnection.visualization.ui.PCEdge@eb7859]
问题:
通过枚举可以发现存在与list.get(0)相对应的Entry,但直接arcsMap.get(list.get(0))返回的却是null

[解决办法]
可以发现存在与list.get(0)相对应的Entry

————————————————————————————————————————-
你是不是自己 看 字符 比较的 ?List里的是对象不是简单字符串8? map是用对象比较的, 也许 你应该重写equals 方法

[解决办法]
同意楼上
[解决办法]
要HashMap才是根据hashCode值来查找的吧

读书人网 >J2SE开发

热点推荐