模仿ArraList的源码
程序代码:
public class test { Object[] obj; int size; public int size() { return size; } public test() { this.test(5); } private void test(int i) { obj = new Object[i]; } public void add(Object o) { if (size==obj.length) { grow(); } obj[size] = o; size++; } private void grow() { Object[] o = new Object[obj.length+10]; for(int i=0;i<size;i++){ o[i] = obj[1]; } obj=o; } public Object get(int i) { return obj[i]; } public void set(int i,Object o) { // TODO Auto-generated method stub for(int j=size;j>i;j--){ obj[j]=obj[j-1]; } obj[i] = o; }