java.util.ConcurrentModificationException & iteration?

前端 未结 3 989
孤独总比滥情好
孤独总比滥情好 2021-01-25 22:28

I\'m so very new to Arraylists & iterators & this is the first time I got this exception. I have an ArrayList u & I\'d like to do the following algorithm:

         


        
3条回答
  •  忘了有多久
    2021-01-25 23:17

    Try this:

    Iterator iter = u.iterator();
    while (iter.hasNext())
    {
        Character currentChar = iter.next();
    
        if(k==1){           //base case
    
            if(isAnswer(s+u.get(0)))
    
            System.out.println(s+u.get(0)+" is the correct sequence."+ '\n');
            return;
        }
    
        else{
             iter.remove();
             puzzleSolve(k-1, s+currentChar  , u);
             u.add(currentChar);
             removeLastChar(s);
        }
    

    }

提交回复
热议问题