list.removeAll(otherList) - wrong result
Hi guys,
I have 2 Lists:
1.carList
2.documentList
*both contain the same type: car PLUS I have overloaded the hashCode and equals of car
carList has 1106 items
documentList has 88 items
I would like to remove the 88 items of documentList from the carList.
(simple math: 1106-88=1018)
By doing this:
(1)
this.carList.removeAll(documentList);
the carList.size() = 1013 (?!?!)
by doing this:
(2)
for (int x=carList.size()-1; x>=0; x--)
{
Car cx = (Car) carList.get(x);
for (int i=documentList.size()-1; i>=0; i--)
{
Car ci = (Car) documentList.get(i);
if (cx.equals(ci))
{
carList.remove(x);
documentList.remove(i);
break;
}
}
}
I get 1018 (correct)
Question: Why am I getting the wrong result in option 1? (once again, I have overloaded the hashCode and equals of car)

