Reviewing custom array List class of java
The CustomArrayList API is inconsistent because I can declare a list of type E to add elements of type E, but when I remove an element from it, I get an Object element:


public Object remove(int index) { /* ... */ }





Inside CustomArrayList you work with Object[] elementData. From the book Effective Java; Item 26 you could change your code to:

class CustomArrayList&lt;E&gt; {

  private E[] elementData;
  /* ... */

  public CustomArrayList() {
    elementData = (E[]) new Object[INITIAL_CAPACITY];
  }

  /* ... */

}




Inside remove you modify elementData in an imperative way. You could use System.arraycopy which would be more deklarative.


public Object remove(int index) {
 /* ... */
 Object removedElement = elementData[index];
 for (int i = index; i &lt; size - 1; i++) {
   elementData[i] = elementData[i + 1];
 }
 /* ... */
}



public E remove(int index) {
  /* ... */

  if (size - 1 - index &gt;= 0)
    System.arraycopy(elementData, index + 1, elementData, index, size - 1 - index);

  /* ... */
}




The methods get and remove contain a code duplication:


public E get(int index) {
 if (index &lt; 0 || index &gt;= size) {
   throw new IndexOutOfBoundsException("Index: " + index + ", Size " + index);
  }
 return (E) elementData[index];
}

public Object remove(int index) {
 if (index &lt; 0 || index &gt;= size) {
   throw new IndexOutOfBoundsException("Index: " + index + ", Size " + index);
 }

 Object removedElement = elementData[index];

 /* ... */

 return removedElement;
}



It is possible to invoke get inside remove like:

public E remove(int index) {
  E elementToRemove = get(index);

  if (size - 1 - index &gt;= 0)
    System.arraycopy(elementData, index + 1, elementData, index, size - 1 - index);

  size--;

  return elementToRemove;
}