Remove odd elements from ArrayList while iterating
<p>I have an ArrayList of Strings and I'm trying to remove the odd elements of the ArrayList, i.e. list.remove(1), list.remove(3), list.remove(5) etc.</p>

<p>This is the code I'm attempting to use which throws up an IllegalStateException error:</p>

<pre><code>int i = 0;
    for (Iterator&lt;String&gt; it = words.iterator(); it.hasNext(); )
    {
        if (i % 2 != 0 &amp;&amp; it.hasNext())
        {
            it.remove();
        }
        i++;
    }
</code></pre>

<p>Is there a better (working) way to do this?</p>
