Hi spigot comunity, i'm trying to interate over an array, i tryed with a interator, for, foreach but the same exception are launched Hi spigot comunity, i'm trying to iterate over an array, i tried with a iterator, for, foreach but the same exception are launched Thank You Code: http://pastebin.com/7fyRkaTK Error: http://pastebin.com/9Gyx3CUN
Try this: Code (Text): public static void removeHgPlayer(Player pl){ boolean remove = false; while(inter.hasNext()){ if(inter.next().getPlayer().equals(pl)){ remove = true; break; } } if(remove){ inter.remove(); // Do other stuff } } Spoiler: Useful information The ConcurrentModificationException happens when you add/remove objects to/from an iterator. The reason why you can't do this is because the normal Collection classes don't utilize so-called Robust Iterators. If you want a robust iterator in Java you need to use CopyOnWriteArrayList or CopyOnWriteArraySet. For your situation, however, using those would be overkill.
What do you mean by "didn't work"? Does it produce any errors? If it's not too much trouble, it'd help a lot if you posted all of your code. EDIT: I see you forgot to add some lines from my code. Copy my code exactly as it is written and it might work.