Java ArrayList.remove() problem
<p>This is part of my code.</p>

<pre><code>Integer keyLocation = reducedFD.indexOf(KeyPlus.get(KEYindex));
someArrayList.remove(keyLocation);
</code></pre>

<p>So what I am doing here is I assign keyLocation(the first occurence of a string in the reducedFD arrayList). But when I want to remove from someArrayList the item with that keyLocation, it will not work. </p>

<p>If I input manually:</p>

<pre><code>someArrayList.remove(0); //Let's say 0 is the actual keyLocation
</code></pre>

<p>This actually works.</p>

<p>What is weird is THAT THE FOLLOWING CODE ALSO WORKS:</p>

<pre><code>someArrayList.remove(keyLocation + 1);
</code></pre>

<p>Any hints?</p>

<p>Here is the main loop:</p>

<pre><code>for (int KEYindex = 0; KEYindex &lt; KeyPlus.size(); KEYindex++){

 Integer keyLocation = reducedFD.indexOf(KeyPlus.get(KEYindex));

if (reducedFD.contains(KeyPlus.get(KEYindex))){

 KeyPlus.add(reducedFD.get(keyLocation+1));
 CheckedAttributesPlus.add(KeyPlus.get(KEYindex));
 reducedFD.remove(keyLocation);

}
}
</code></pre>
