title: concurrentmodification exception -- setting an array element
body: <p>I read in JAVAdocs that concurrent modification exception comes when you structurally modify a list while iterating through it.In my case I am not changing the size of array but,just replacing some indices in the array. Tried out many things but this doesnt seem to work.</p>
  
  <p>Providing a snippet below.(The code is a recursive function to solve n-queens problem)</p>
  
  <pre><code>    public ArrayList&lt;ArrayList&lt;String&gt;&gt; solve(int a, String[] arr,int beg,
  ArrayList&lt;ArrayList&lt;String&gt;&gt; result) {      
      for( int i=beg;i&lt; a*a ;i++){
          String s = arr[i];
          if(s.equals(".")){
              //fill Q and look for valid combs
             arr[i] = "Q";
             if(i== (a*a)-1){
                   String[] t = (String[])(arr.clone());
                   result.add(new ArrayList&lt;String&gt;(Arrays.asList(t)));
             }else{
                 ArrayList&lt;Integer&gt; filled = fillX(arr,i,a,"x");//this function fills "X" in queen's path and returns the filled indices
  
                 ArrayList&lt;ArrayList&lt;String&gt;&gt; tmp = solve(a,arr,i+1,result);
                 if(!tmp.isEmpty()){
                      for(ArrayList&lt;String&gt; t :tmp){
                          result.add((ArrayList&lt;String&gt;)t.clone());
                       }
                 }
                  for(int x = 0;x&lt; a*a;x++){                      
                      if(filled.contains(x)){
                          arr[x] = ".";//the exception goes away on removing this line
                      }                         
                  }                 
             }
             arr[i] =".";
          }
      }
          return result;  
  }
  </code></pre>
  
  <p>Stacktrace --</p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
  at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
  at java.util.ArrayList$Itr.next(ArrayList.java:851)
  at Solution.solve(Solution.java:29)
  at Solution.solveNQueens(Solution.java:7)
  at Main.main(Main.java:323)
  </code></pre>