1: public void add(int newPosition, T newEntry) 2: { 3: checkInitialization(); 4: if ((newPosition >= 1) && (newPosition <= numberOfEntries + 1)) 5: { 6: if (newPosition <= numberOfEntries) 7: makeRoom(newPosition); 8: list[newPosition] = newEntry; 9: numberOfEntries++; 10: ensureCapacity(); // Ensure enough room for next add 11: } 12: else 13: throw new IndexOutOfBoundsException( 14: "Given position of add's new entry is out of bounds."); 15: } // end add 16: private void makeRoom(int newPosition) 17: { 18: int newIndex = newPosition; 19: int lastIndex = numberOfEntries; 20: for (int index = lastIndex; index >= newIndex; index--) 21: list[index + 1] = list[index]; 22: } // end makeRoom 23: 24: // Version 4.0