java - Need to Remove From List at Specified Multiple Indices, without new-size problems -


this question has answer here:

i have array of indices @ elements must removed list, e.g.: (4), (7), (8).

the problem is:

1) can't use for-loop, size changes after each delete (arraylist.remove(i))

2) can't use iterator updated counter, counter not work anymore (iterator.remove()).

found nice solution here: remove multiple elements arraylist

collections.sort(indices, collections.reverseorder()); (int : indices)     strs.remove(i); 

that seems fast , simple solution. reverse-sort first, go through indices , remove.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -