src/share/classes/java/util/ArrayList.java

Print this page




 592         int numMoved = size - index;
 593         if (numMoved > 0)
 594             System.arraycopy(elementData, index, elementData, index + numNew,
 595                              numMoved);
 596 
 597         System.arraycopy(a, 0, elementData, index, numNew);
 598         size += numNew;
 599         return numNew != 0;
 600     }
 601 
 602     /**
 603      * Removes from this list all of the elements whose index is between
 604      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 605      * Shifts any succeeding elements to the left (reduces their index).
 606      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 607      * (If {@code toIndex==fromIndex}, this operation has no effect.)
 608      *
 609      * @throws IndexOutOfBoundsException if {@code fromIndex} or
 610      *         {@code toIndex} is out of range
 611      *         ({@code fromIndex < 0 ||
 612      *          fromIndex >= size() ||
 613      *          toIndex > size() ||
 614      *          toIndex < fromIndex})
 615      */
 616     protected void removeRange(int fromIndex, int toIndex) {
 617         modCount++;
 618         int numMoved = size - toIndex;
 619         System.arraycopy(elementData, toIndex, elementData, fromIndex,
 620                          numMoved);
 621 
 622         // clear to let GC do its work
 623         int newSize = size - (toIndex-fromIndex);
 624         for (int i = newSize; i < size; i++) {
 625             elementData[i] = null;
 626         }
 627         size = newSize;
 628     }
 629 
 630     /**
 631      * Checks if the given index is in range.  If not, throws an appropriate
 632      * runtime exception.  This method does *not* check if the index is




 592         int numMoved = size - index;
 593         if (numMoved > 0)
 594             System.arraycopy(elementData, index, elementData, index + numNew,
 595                              numMoved);
 596 
 597         System.arraycopy(a, 0, elementData, index, numNew);
 598         size += numNew;
 599         return numNew != 0;
 600     }
 601 
 602     /**
 603      * Removes from this list all of the elements whose index is between
 604      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 605      * Shifts any succeeding elements to the left (reduces their index).
 606      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 607      * (If {@code toIndex==fromIndex}, this operation has no effect.)
 608      *
 609      * @throws IndexOutOfBoundsException if {@code fromIndex} or
 610      *         {@code toIndex} is out of range
 611      *         ({@code fromIndex < 0 ||

 612      *          toIndex > size() ||
 613      *          toIndex < fromIndex})
 614      */
 615     protected void removeRange(int fromIndex, int toIndex) {
 616         modCount++;
 617         int numMoved = size - toIndex;
 618         System.arraycopy(elementData, toIndex, elementData, fromIndex,
 619                          numMoved);
 620 
 621         // clear to let GC do its work
 622         int newSize = size - (toIndex-fromIndex);
 623         for (int i = newSize; i < size; i++) {
 624             elementData[i] = null;
 625         }
 626         size = newSize;
 627     }
 628 
 629     /**
 630      * Checks if the given index is in range.  If not, throws an appropriate
 631      * runtime exception.  This method does *not* check if the index is