Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果arraylist中没有缺少的记录,请将其添加到arraylist中_Java_Arraylist - Fatal编程技术网

Java 如果arraylist中没有缺少的记录,请将其添加到arraylist中

Java 如果arraylist中没有缺少的记录,请将其添加到arraylist中,java,arraylist,Java,Arraylist,请原谅,我是一个编程新手。我已经试着研究如何将一些丢失的记录添加到列表中,但似乎仍然无法将其正确地放入我的代码中 我有两个具有不同结果集的ArrayList。也就是说,第一个是用另一种方法导出的,并存储在abcList中。然后,此列表在我当前的fixChartStats方法中作为参数使用 在我的代码中,我将使用从fixChartStats方法中的hql查询派生的第二个列表检查abcList中的相应记录 如果记录对应,那么我将执行如下所示的必要操作来更新ApprovedCount编号等,否则我将其

请原谅,我是一个编程新手。我已经试着研究如何将一些丢失的记录添加到列表中,但似乎仍然无法将其正确地放入我的代码中

我有两个具有不同结果集的ArrayList。也就是说,第一个是用另一种方法导出的,并存储在abcList中。然后,此列表在我当前的fixChartStats方法中作为参数使用

在我的代码中,我将使用从fixChartStats方法中的hql查询派生的第二个列表检查abcList中的相应记录

如果记录对应,那么我将执行如下所示的必要操作来更新ApprovedCount编号等,否则我将其设置为0

如何将第二个列表中缺少的记录添加到第一个arraylist(即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);
        }
    }
}
private void fixChartStats(List abcList、Map param、List issueList、List destList)引发异常{
//初始化hql查询
//将对象[]中的所有字段转换为单个变量
第一行=真;
for(选项卡模型abc:abcList){
如果(abc.getId().getAbcYear()=abcYear&&
abc.getId().getAbcMonthId()=abcMonthId&&
abc.getId().getAbcApplAccnId().getAccnId().equalsIgnoreCase(abcApplAccnId.getAccnId()){
如果(第一行){
abc.setApprovedCount(ABCAPApprovedCount);
abc.设置取消计数(abcCancelledCount);
第一行=假;
}否则{
abc.setApprovedCount(0);
abc.SetCanceledCount(0);
}
}否则{
//如何在这里做必要的工作
//下面是我试过的
abcList.add(abc);
}
}
}

调试时,我注意到它被添加到列表中。但添加后不久,ConcurrentModificationException被抛出。

创建一个本地列表并向其中添加缺少的记录,然后将本地列表中的所有元素添加到abcList

List<TAbcModel> temp = new ArrayList<>();
后循环

abcList.addAll(temp);

当你在一个列表上迭代时,你不能修改它,请看,谢谢,伙计。这确实解决了问题,谢谢!
abcList.addAll(temp);