ArrayList:
package com.tn.arraylist; public class ArrayList { Object[] objects=new Object[10];
int index=0; public void add(Object o){
if(index==objects.length){
Object[] newobjects=new Object[objects.length*2];
System.arraycopy(objects, 0, newobjects, 0, index);
objects=newobjects;
}
objects[index++]=o;
} public int size(){
return index;
} }
客户端测试类Test:
package com.tn.arraylist; public class Test {
public static void main(String[] args) {
ArrayList al=new ArrayList();
for(int i=0;i<34;i++){
al.add(new Object());
}
System.out.println(al.size());
}
}