Can someone tell me the reason why when my code loops through an Array List looking for duplicates to delete it skips over some blatant duplicates?
>>58971922
Well if you give us the full code then maybe?
I know almost nothing about coding but I'm American so I'll reply anyway.
Is the equals method really the way to go? Does that check for equality or identity?
>>58971950
That's basically all that is written out on code, for now, other than my test contents for the Array List which is nearly 300 numbers long.
what's in your array list? what does your equals function look like?
>>58971922
Each delete change index number.
Using TreeSet to get non- duplicate list.
In case you want same orden non-duplicates.
Create one array list,one tree set.
Iterate array list of data
If X element don't exist on tree, add tree and array list, if element exist on tree do nothing.
>>58972016
Beat me to it. Pretty simple, OP is removing indexes thus skipping over some as the array shortens.
>>58972023
Ahh yes makes sense seeing as the .remove is subtracting one from the indices of every number following the last duplicate.
>>58971922
That's blatantly obvious : It's because you don't know what you're doing!
>>58972016
>>58972023
basically this
you're modifying an array *as you're looping over it*. so your array is changing during your loop, messing with shit.
Though not the most elegant solution, just starting the inner loop from the back of the list should work.
Functional programming doesn't have this problem.
>>58971922
>>58972042
>>58972016
use an iterator. this will avoid that problem. like so:Iterator iter = list.iterator();
while(iter.hasNext()) {
Object obj = iter.next();
if (condition) {
iter.remove();
}
}