import java.util.Collection;
public class MyArrayList {
//存放数据的数组
private E[] obj;
// 存放元素的个数
private int index;
//数组的容量
private int capcity =5;
//容量递增量 大概就是这个有点难度
private int offset =5;
public MyArrayList(){
obj = (E[]) new Object[capcity];
}
public MyArrayList(int intCapcity){
this.capcity = intCapcity;
obj = (E[]) new Object[capcity];
}
public MyArrayList(Collection col){
this.capcity =col.size();
obj = (E[]) n
ew Object[capcity];
System.arraycopy(col,0,obj,0,col.size());
}
public int size() {
return this.size();
}
public boolean isEmpty(){
return index =0?ture:false;
}
public void clear() {
this.capcity = 5;
obj = (E[]) new Object[capcity];
this.index = 0;
}
public E get(int x) {
try {
if(x >= index){
throw (new ArrayIndexOutOfBoundsException());
}
}
catch (ArrayIndexOutOfBoundsException ex) {
ex.prinStackTrace();
}
return null;
}
publci boolean add(E o) {
boolean bool = false ;
//要等于容量大小
if(index ==this.capcity){
this.capcity +=this.offset;
E[] temp = (E[])new Object[this.capcity];
System.arraycopy(obj,0,temp,0,index);
this.obj =temp;
}
obj[index++] = o;
return bool;
}
} |