import java.util.Collections;输出:
导入 java.util.Vector;
public class 复制 {
public static void main(String[] args) {
Vectorv1 = new Vector ();
v1.add(a”);
v1.add(b”);
v1.add(c”);
v1.add(d”);
v1.add(e”);
Vectorv2 = new Vector (5);
v2.add(a2”);
v2.add(b2”);
v2.add(c2”);
v2.add(d2”);
v2.add(e2”);
System.out.println(v2(before): ”+v2);
Collections.copy(v2, v1);
System.out.println(v2(after): ”+v2);
}
}
v2(before): [a2, b2, c2, d2], e2]
v2(after): [a, b, c, d, e]
注意:Collections.copy() 会引发异常,因为此方法会逐个下标复制下标,而不会分配内存并增加 v1. |
Please disable your ad blocker and refresh the window to use this website.