import java.util.Collections;Ausgabe:
import java.util.Vector;
public class Copy {
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(vorher): "+v2);
Sammlungen.copy(v2, v1);
System.out.println("v2(after): "+v2);
}
}
v2(vorher): [a2, b2, c2, d2, e2]
v2(nachher): [a, b, c, d, e]
Hinweis: Die Collections.copy() löst eine Ausnahme aus, wenn der zweite Vektor v2 leer ist oder seine Größe nicht mit der Größe von v1 übereinstimmt, da diese Methode Index für Index kopiert, ohne Speicher zuzuweisen und die Kapazität von v1. |
Please disable your ad blocker and refresh the window to use this website.