Skip to content

Instantly share code, notes, and snippets.

@MagIciaNGTAO
Created April 30, 2014 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MagIciaNGTAO/8cc30837e83d7dcb8eff to your computer and use it in GitHub Desktop.
Save MagIciaNGTAO/8cc30837e83d7dcb8eff to your computer and use it in GitHub Desktop.
ConcurrentModificationException
private class Itr implements Iterator<E> {
int cursor; // index of next element to return
int lastRet = -1; // index of last element returned; -1 if no such
int expectedModCount = modCount;
public boolean hasNext() {
return cursor != size;
}
@SuppressWarnings("unchecked")
public E next() {
checkForComodification();
int i = cursor;
if (i >= size)
throw new NoSuchElementException();
Object[] elementData = ArrayList.this.elementData;
if (i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i + 1;
return (E) elementData[lastRet = i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment