public class VectorDemo {
public static void main(String[] args) {
// 创建集合对象
Vector v = new Vector();
// 添加元素
v.addElement("hello");
v.addElement("world");
v.addElement("java");
// 遍历
// System.out.println(v.elementAt(0));
// System.out.println(v.elementAt(1));
// System.out.println(v.elementAt(2));
for (int x = 0; x < v.size(); x++) {
String s = (String) v.elementAt(x);
System.out.println(s);
}
System.out.println("----------------");
//public Enumeration elements()
Enumeration en = v.elements();
while(en.hasMoreElements()){
String s = (String)en.nextElement();
System.out.println(s);
}
}
}
|