Removing every 2nd element in array list : <p>I've been trying so far to write a method ,removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. But so far I've been getting a IndexOutOfBoundsException and I don't know why.</p>

<p>Any help would be appreciated</p>

<pre><code>public static ArrayList&lt;String&gt; removeEvenLength(ArrayList&lt;String&gt; list) {
int size = list.size();
ArrayList&lt;String&gt; newLst = new ArrayList&lt;String&gt;();

for (int x = 0; x &lt; size; x++) {
    if (list.get(x).length() % 2 == 0) {
        list.remove(x);
    }
}

return list;
</code></pre>

<p>}</p>
