从 list 中 取出对象//用来保存 id 和 count ; HashMap hm = new HashMap ();for(Iterator it = list.iterator; it.hasNext();) { Peoplecomment p = (Peoplecomment )it.next();
int id = p.getId(); //判断hm 是否有你添加的那个编号id if(hm.containsKey(id)) { int count=Integer.parseInt(hm.get(id).toString()) ; //存在 评论数 加 1; hm.put(id,count++);
HashMap hm = new HashMap ();for(Iterator it = list.iterator; it.hasNext();)
{
Peoplecomment p = (Peoplecomment )it.next();
int id = p.getId();
//判断hm 是否有你添加的那个编号id
if(hm.containsKey(id))
{
int count=Integer.parseInt(hm.get(id).toString()) ;
//存在 评论数 加 1;
hm.put(id,count++);
} else{
//不存在,就是第一个
hm.put(id,1);
}
}经过上面的过程后 ,hm 中就保存了 id 和 count 的一一对应关系。
然后迭代出 hm 就可以的出你要的结果。
你自己做一下适当的调整。。
顶下,还没有明白你说的意思!