自己实现数据结构---ArrayList
1.先上代码: public class ArrayList<E> { private E[] data; private int size; /** * 构造方法,初始化容量capacity * @param capacity */ public ArrayList( int capacity){ data = (E[]) new Object[capacity]; size = 0 ; } /** * 默认的构造方法,默认capacity=10 */ public ArrayList(){ this (10 ); } /** * 获取数组中元素的个数 * @return */ public int getSize(){ return size; } /** * 获取数组的容量 * @return */ public int getCapacity(){ return data.length; } /** * 判断数组是否为空 * @return */ public boolean isEmpty(){ return size == 0 ; } /** * 在第index位置插入一个新元素 * @param index * @param e */ public void add( int index,E e){ if (index < 0 || index > size){