ArrayList: remove an object during for loop
<p>I have a little problem. I'm trying to remove an object from ArrayList, but the change doesn't occur. </p>

<p>Here is the code sample: </p>

<pre><code>    List&lt;Room&gt; rooms = new CopyOnWriteArrayList&lt;Room&gt;();

    rooms.addAll(fp.getRooms());
    int counter = 1;

    for(Room r: rooms){
        for(Square s: r.getDoor()){
            r.getDoor().remove(s);
            String name = String.valueOf(fp.getRooms().size() + counter);
            Room doorRoom = new Room(name, false, s, s);
            rooms.add(doorRoom);
            counter++;
        }
    }

    fp.setRooms(rooms);
</code></pre>

<p>I'm trying to remove the object <code>s</code> and replace it with a new object <code>doorRoom</code>. </p>

<p>Output: </p>

<pre>
First> [S: 11:7; true, S: 11:15; true, S: 11:20; true]
Second> [S: 11:7; true, S: 11:15; true, S: 11:20; true]
</pre>

<p>And I'm expecting:</p>

<pre>
First> [S: 11:7; true, S: 11:15; true, S: 11:20; true]
Second> [S: 11:15; true, S: 11:20; true]
</pre>

<p>an so on... </p>

<p>What is the problem?</p>

<p>Thank you and I'll be glad to receive your response! </p>
