可以把需要的东西存到map中
map的key会自动去重
containsKey()来比较;
Map<Long,Integer> pfwMap = new HashMap(); for (Iterator iterator = pfw.iterator();iterator.hasNext();) { Customerflow Cfw =(Customerflow) iterator.next(); if (pfwMap.containsKey(Cfw.getDate())) { Integer k = pfwMap.get(Cfw.getDate())+Cfw.getSum(); pfwMap.put(Cfw.getDate(),k); }else { pfwMap.put(Cfw.getDate(), Cfw.getSum()); } }
可以用keySet 来取出map中的key值。 然后再用get(key)就可以取出value
Set<Long> keySet = pfwMap.keySet(); totalListInfo = new ArrayList(); for (Iterator<Long> it = keySet.iterator(); it.hasNext();) { Long nxt = it.next(); Customerflow C = new Customerflow(); C.setDate(nxt); C.setSum(pfwMap.get(nxt)); totalListInfo.add(C); }
最新评论