Java ArrayList.remove() problem

The problem is you are passing an Integer to the remove method, and not an int. When you pass an Integer, it assumes that the Integer itself is what you are trying to remove, not the value at that index. Compare the methods

remove(Object o)
remove(int i)

so do:

int keyLocation = reducedFD.indexOf(KeyPlus.get(KEYindex));
someArrayList.remove(keyLocation);

Here is short description :

remove(Object o) // remove object
remove(int index) // remove the object in that index

if you write .remove(5) compiler understands it as a primitive type so as a index and remove index(5). If you want to remove object you should write .remove(new Integer(5))

Tags:

Java