public class MyArrayList<T> {
private static final int DEFAULT_SIZE = 10;
private Object[] elements;
private int count = -1;
public MyArrayList(){
elements = new Object[DEFAULT_SIZE];
}
public int size(){
return count+1;
}
public void add(T t){
count++;
if(count<elements.length){
elements[count] = t;
}else{
Object[] newArray = new Object[elements.length+DEFAULT_SIZE];
for(int i=0;i<elements.length;i++){
Object o = elements[i];
newArray[i] = o;
}
elements = newArray;
elements[count] = t;
}
}
@SuppressWarnings("unchecked")
public T get(int index){
return (T) this.elements[index];
}
}