Javaでベクターを配列に変換する
ベクターから配列にすべての要素をコピーするには、作成した配列オブジェクトを
copyInto().
import java.util.Vector;
public class VectorToArray {
public static void main(String[] args) {
Vector<文字列>vct = new Vector です<文字列>();
//要素を追加
vct.add("un");
vct.add("2");
vct.add("three");
vct.add("4");
System.out.println("ベクトル:");
for(String e:vct)
System.out.println(e);
文字列[] copyArr = new String[vct.size()];
vct.copyInto(copyArr);
System.out.println("コピーされたアイテム:");
for(String e:copyArr){
System.out.println(e);
}
}
}
Runtime:
Vector:
one
two
threebr />four<
コピーされたアイテム:
one
two
three
four