Arrays arraylist中的错误 testSed4=sedenia4.get(0); while(it8.hasNext()){ tempRozdiel=it8.next(); tempSed4=it7.next(); if(testSed4.equals(tempSed4)){ testSed4=tempSed4; casy.add(坦普罗兹代尔); }否则{ 卡西·阿德(霍德诺塔); testSed4=tempSed4; } } 对于(int j=0;j

Arrays arraylist中的错误 testSed4=sedenia4.get(0); while(it8.hasNext()){ tempRozdiel=it8.next(); tempSed4=it7.next(); if(testSed4.equals(tempSed4)){ testSed4=tempSed4; casy.add(坦普罗兹代尔); }否则{ 卡西·阿德(霍德诺塔); testSed4=tempSed4; } } 对于(int j=0;j,arrays,object,loops,arraylist,iterator,Arrays,Object,Loops,Arraylist,Iterator,为什么第行有错误:tempRozdiel=it8.next() 这段代码有什么不好的地方 testSed4 = sedenia4.get(0); while (it8.hasNext()) { tempRozdiel = it8.next(); tempSed4 = it7.next(); if (testSed4.equals(tempSed4)) { testSed4 = tempSed4;

为什么第行有错误:tempRozdiel=it8.next()

这段代码有什么不好的地方

    testSed4 = sedenia4.get(0);

    while (it8.hasNext()) {
        tempRozdiel = it8.next();
        tempSed4 = it7.next();

        if (testSed4.equals(tempSed4)) {
            testSed4 = tempSed4;
            casy.add(tempRozdiel);
        } else {
            casy.add(hodnota);
            testSed4 = tempSed4;
        }
    }
    for (int j = 0; j < casy.size(); j++) {
        System.out.println(casy.get(j) + " casy");
    }
您只检查
it8
是否有下一个元素,而不检查
it7

此外,如果
it7
it8
是此对象上的迭代器,则不能使用
casy.add()

您只检查
it8
是否有下一个元素,而不检查
it7


此外,如果
it7
it8
是此对象上的迭代器,则不能使用
casy.add()

异常情况发生,因为您正在修改在迭代循环体中迭代的集合


这就是为什么您从迭代器中获得了
ConcurrentModificationException
。next()

异常发生的原因,因为您正在修改它在迭代循环体中迭代的集合


这就是为什么您从迭代器.next()中得到了
ConcurrentModificationException
,您得到了什么样的错误?如果是nullpointerexception,您忘记初始化it8 arraylist对象。线程“main”中的异常java.util.ConcurrentModificationException位于java.util.arraylist$Itr.checkForComodification(arraylist.java:819)位于java.util.arraylist$Itr.next(arraylist.java:791)位于AppIdentificationSession.AppIdentificationSession.main(AppIdentificationSession.java:36)Java结果:1我无法在这里获得完整的代码,因为:“哦!您的问题无法提交,因为:您的帖子没有太多的上下文来解释代码部分;请更清楚地解释您的场景。”有什么不好?AppIdentificationSession.Java:36是包含tempRozdiel=it8.next()的行;什么类型的
tempRozdiel
和迭代器?会出现什么类型的错误?如果是nullpointerexception,您忘记初始化it8 arraylist对象。线程“main”中的异常java.util.ConcurrentModificationException位于java.util.arraylist$Itr.checkForComodification(arraylist.java:819)位于java.util.arraylist$Itr.next(arraylist.java:791)位于AppIdentificationSession.AppIdentificationSession.main(AppIdentificationSession.java:36)Java结果:1我无法在这里获得完整的代码,因为:“哦!您的问题无法提交,因为:您的帖子没有太多的上下文来解释代码部分;请更清楚地解释您的场景。”有什么不好?AppIdentificationSession.Java:36是包含tempRozdiel=it8.next()的行;什么类型的
tempRozdiel
和迭代器?@Majkl 1st off我们不知道您的代码中发生了什么,因为您提供的信息不够。在此操作(您发布)期间,某些内容更改了您的列表。About
at8
iterator:post关于这个列表的信息while(it1.hasNext()){ipecka=it1.next();agentik=it2.next();spolu=ipecka+agentik;ipagent.add(spolu);}在这个代码中可以吗,为什么不在下一个代码中?我有第一个list_会话,它包含1,2,2,3。第二个list_时间包含30,17,25,46。当list_会话的第二个元素等于第一个元素时,然后将这一次添加到第三个列表中,否则添加-1。第三个元素和第四个元素也是如此。@Majkl 1st off我们不知道您的代码中发生了什么,因为您提供的信息不够。在此操作(您发布)期间,某些内容更改了您的列表。About
at8
iterator:post关于这个列表的信息while(it1.hasNext()){ipecka=it1.next();agentik=it2.next();spolu=ipecka+agentik;ipagent.add(spolu);}在这个代码中可以吗,为什么不在下一个代码中呢?我有第一个列表会话,它包含1,2,2,3。第二个列表会话时间包含30,17,25,46。当列表会话的第二个元素等于第一个元素时,将这一次添加到第三个列表会话中,否则添加-1。第三个元素和第四个元素相同,以此类推。
while (it8.hasNext()) {
    tempRozdiel = it8.next();
    tempSed4 = it7.next();