import java.util.Vector;
import java.util.Iterator;
import java.util.Arrays;
import java.util.ArrayList;
public class VectorDemo{
public static void main(String args[]){
String names[]={"hfdsfng", "zhfcinyafdn"};
String namesp[]=new String[]{"hv heng", "zhavxcyan"};
Vector<String> v1=new Vector<String>(
Arrays.asList("hujghfgeng", "zhagfyan", "huaxvvidong")
);
Vector<String> v2=new Vector<String>(Arrays.asList(names));//Arrays.asList()返回List列表(继承了Collection)
Vector<String> v3=new Vector<String>(new ArrayList<String>(){//匿名类的初始化,ArrayLists类实现了Collection接口
{
add("hujunzheng");
add("zhangjinyan");
}
});
//三种实现遍历Vector的方法
System.out.println("V1向量:");
for(Object tmp : v1.toArray()){
System.out.println((String)tmp);
}
System.out.println("V2向量:");
for(Iterator<String>it = v2.iterator(); it.hasNext(); ){
System.out.println(it.next());
}
System.out.println("V3向量:");
for(int i=0; i<v3.size(); ++i){
System.out.println(v3.elementAt(i));
}
}
}