数组模拟ArrayList

 
   
public class myArrayList {
String[] a1=new String[5];
int size;
//public boolean[] get;
public void add(String a){
if (a1.length==size){

String[] temp=new String[a1.length+5];
System.arraycopy(a1,0,temp,0,a1.length);
a1=temp;
}
a1[size++]=a;
}
public int size(){
return size;
}
public String get(int i){
return a1[i];
}
}

你可能感兴趣的:(数组模拟ArrayList)