to Andrawu(晓彬) 不用运行就能看出你的程序会抛ArrayIndexOutOfBoundsException
newVector.addAll(int index, oldVector);
to: farawayzheng_necas(遥远) 代码没有经过测试我是不会帖的,你试试吧!
Andrawu(晓彬)的没错。 public List subList(int fromIndex, int toIndex) fromIndex - low endpoint (inclusive) of the subList. toIndex - high endpoint (exclusive) of the subList. 所以把第二个和第三个复制过去了,怎么会抛异常!
v.add("1111") ;
v.add("2222") ;
v.add("3333") ;
java.util.List list = v.subList(1,3) ;
java.util.Vector vCopy = new java.util.Vector() ;
vCopy.addAll(list) ;
for(int i=0;i<vCopy.size();i++)
System.out.println(vCopy.get(i)) ;
代码没有经过测试我是不会帖的,你试试吧!
public List subList(int fromIndex,
int toIndex)
fromIndex - low endpoint (inclusive) of the subList.
toIndex - high endpoint (exclusive) of the subList.
所以把第二个和第三个复制过去了,怎么会抛异常!
要想完全独立的产生一个新的备份,而不受原来的影响.就得考虑clone(),而且如果是自己写的类,必须考虑他所有成员变量的clone.