[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Array List

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 1

File: Capture.png (13KB, 1021x314px) Image search: [Google]
Capture.png
13KB, 1021x314px
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();
}
}
Thread posts: 13
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.