0

my main problem is the "ConcurrentModificationException". I want to remove a row, when it's found. but my list isn't updated after removing the row. So i get the the flaw. I don't know how to solve it. I read already here, google, some books but i don't know how to resolve it with an object[] in a list.... that's to much for me

Or is it better to use another data structur for sorting and searching, if yes, which one would be fine?(there is much data in the list object[]) And how could i convert it to that data structure?

Sorry for beginner questions... Thanks for helping answers!

List<Object[]> allIds is a param;

            for (Object[] privateIds : allIDs) {


        for (Object[] comparePrivateIdS : allIds) {

            if (privateIds[1].equals(comparePrivateIdS[1]) && privateIds[2].equals(comparePrivateIdS[2])) {
                System.out.print("ok");

                int index = allIds.indexOf(comparePrivateIdS);
                allIds.remove(comparePrivateIdS);

            } else {
                System.out.println("Do Nothing");
            }
        }
speedyG
  • 33
  • 9
  • See http://stackoverflow.com/questions/1675037/removing-items-from-a-collection-in-java-while-iterating-over-it – DirkyJerky May 23 '14 at 14:00

1 Answers1

1

You may not call allIds.remove(...) while iterating over allIds, this throws the ConcurrentModificationException. Instead, you must use an explicit iterator and call its remove method:

for (Iterator<Object[]> it = allIds.iterator(); it.hasNext();) {
    Object[] comparePrivateIdS = it.next();
   //...
   if(...) it.remove();
}
gexicide
  • 38,535
  • 21
  • 92
  • 152