MyArraylist :
public class MyArraylist <T> {
private T[] arr;
private int size;
private static final int CAPACITY = 10;
public MyArraylist() {
this(CAPACITY);
}
public int getSize() {
return size;
}
public MyArraylist(int n) {//判断n是否符合要求,需要异常处理
size = 0;
if (n < 0) {
try {
throw new Exception();
} catch (Exception e) {
System.out.println(n + "不能为负数");
}
}
arr = (T[]) new Object[n];
}
private void grow() {
int oldCapacity = arr.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
arr = Arrays.copyOf(arr, newCapacity);
}
private void isfull() {
if (arr.length == size) {
grow();
} else {
return;
}
}
/**