??????????????????е???????????????????Iterator??remove()???????

?????????????ArrayList??????Iterator???????????

    privateclass Itr implements Iterator<E> { 
        /**
    ?????????????????????????????α?????????????List??????????
         *Indexofelementtobereturnedbysubsequentcalltonext.
         */ 
        intcursor = 0; 
     
        /**
         *Indexofelementreturnedbymostrecentcalltonextor
         *previous. Resetto-1ifthiselementisdeletedbyacall
         *toremove.
    ???????????????????????????????-1
         */ 
        intlastRet = -1; 
     
        /**
    ????ArrayList???????
    protected transient int modCount = 0;
        ????????ArrayList??????????????????????????£????????????????
         *ThemodCountvaluethattheiteratorbelievesthatthebacking
         *Listshouldhave. Ifthisexpectationisviolated??theiterator
         *hasdetectedconcurrentmodification.
         */ 
        intexpectedModCount = modCount; 
    //????α???д?List???磬??????????? 
        publicboolean hasNext() { 
                returncursor != size(); 
        } 
    //??????????????α?+1???????? ?= ??????????????? 
        public E next() { 
                checkForComodification(); 
            try { 
           E next = get(cursor); 
           lastRet = cursor++; 
           return next; 
            } catch (IndexOutOfBoundsException e) { 
           checkForComodification(); 
           thrownew NoSuchElementException(); 
            } 
        } 
    /*
    ?????????????????????????α?-1???????List?????????????????λ??
    */ 
        publicvoid remove() { 
            if (lastRet == -1) 
           thrownew IllegalStateException(); 
                checkForComodification(); 
     
            try { 
           AbstractList.this.remove(lastRet); 
           if (lastRet < cursor) 
               cursor--; 
           lastRet = -1; 
           expectedModCount = modCount; 
            } catch (IndexOutOfBoundsException e) { 
           thrownew ConcurrentModificationException(); 
            } 
        } 
     
        finalvoid checkForComodification() { 
            if (modCount != expectedModCount) 
           thrownew ConcurrentModificationException(); 
        } 
        }

privateclass Itr implements Iterator<E> {     /** ?????????????????????????????α?????????????List??????????      *Indexofelementtobereturnedbysubsequentcalltonext.      */     intcursor = 0;      /**      *Indexofelementreturnedbymostrecentcalltonextor      *previous. Resetto-1ifthiselementisdeletedbyacall      *toremove. ???????????????????????????????-1      */     intlastRet = -1;      /** ????ArrayList??????? protected transient int modCount = 0;     ????????ArrayList??????????????????????????£????????????????      *ThemodCountvaluethattheiteratorbelievesthatthebacking      *Listshouldhave. Ifthisexpectationisviolated??theiterator      *hasdetectedconcurrentmodification.      */     intexpectedModCount = modCount; //????α???д?List???磬???????????     publicboolean hasNext() {             returncursor != size();     } //??????????????α?+1???????? ?= ???????????????     public E next() {             checkForComodification();         try {        E next = get(cursor);        lastRet = cursor++;        return next;         } catch (IndexOutOfBoundsException e) {        checkForComodification();        thrownew NoSuchElementException();         }     } /* ?????????????????????????α?-1???????List?????????????????λ?? */     publicvoid remove() {         if (lastRet == -1)        thrownew IllegalStateException();             checkForComodification();          try {        AbstractList.this.remove(lastRet);        if (lastRet < cursor)            cursor--;        lastRet = -1;        expectedModCount = modCount;         } catch (IndexOutOfBoundsException e) {        thrownew ConcurrentModificationException();         }     }      finalvoid checkForComodification() {         if (modCount != expectedModCount)        thrownew ConcurrentModificationException();     }     }