请原谅我,因为我在编程方面还是个初学者。我尝试过研究如何将一些缺失的记录添加到列表中,但似乎仍然不能正确地将其放入我的代码中。
我有两个具有不同结果集的ArrayLists。比方说,第一个是用其他方法派生的,并存储在abcList中。然后,这个列表在我当前的fixChartStats方法中用作一个参数。
在我的代码中,我将使用从fixChartStats方法中的hql查询派生的第二个列表来检查abcList中的相应记录。
如果记录对应,那么我将执行如下所示的必要操作来更新ApprovedCount编号等,否则将其设置为0。
如何添加我进入第一个数组列表(即abcList)的第二个列表中缺失的记录?这里有没有人能说点什么?如果我的问题不清楚,一定要让我知道。提前谢谢,伙计们!
private void fixChartStats(List<TAbcModel> abcList, Map<String, Object> param, List<IssueModel> issueList, List<DestModel> destList) throws Exception {
//initialize the hql query
//translate all fields from Object[] into individual variable
firstRow = true;
for (TAbcModel abc : abcList) {
if (abc.getId().getAbcYear() = abcYear &&
abc.getId().getAbcMonthId() = abcMonthId &&
abc.getId().getAbcApplAccnId().getAccnId().equalsIgnoreCase(abcApplAccnId.getAccnId()) {
if (firstRow) {
abc.setApprovedCount(abcApprovedCount);
abc.setCancelledCount(abcCancelledCount);
firstRow = false;
} else {
abc.setApprovedCount(0);
abc.setCancelledCount(0);
}
}else{
// How to do the necessary here
// Below is what I've tried
abcList.add(abc);
}
}
}
当我调试时,我注意到它被添加到列表中。但在添加之后不久,ConcurrentModificationException就被抛出了。
发布于 2019-05-29 17:44:20
创建本地列表并向其中添加缺少的记录,然后将本地列表中的所有元素添加到abcList中
List<TAbcModel> temp = new ArrayList<>();
在你的循环中:
} else {
temp.add(abc);
}
after循环
abcList.addAll(temp);
https://stackoverflow.com/questions/56357397
复制相似问题