日期:2014-05-20 浏览次数:21127 次
private Type[] theItems;//当前数组
private int size;//实际大小
public boolean add(Type x){
if(theItems.length==size){//数组容量满
Type[] old = theItems;
theItems = (Type[]) new Object[size*2+1];//这行怎么都不理解,编译能通过是因为类型擦除,但是运行
//的时候假如类型参数是String,Object[]如何强转成String[]???
for(int i=0;i<size;i++)
theItems[i] = old[i];//循环复制元素
}
theItems[size++] = x;//插入元素
return true;
}