Java - 使用枚举浏览向量
下面的示例显示了如何浏览和显示 Vector使用对象 枚举。获取项目列表是通过调用elements(),要访问元素,您需要调用 nextElement().
import java.util.Enumeration;运行时:
导入 java.util.Vector;
public class Iterate_Vector_Enumeration {
public static void main(String[] args) {
Vectorvct = new Vector ();
//添加元素
vct.add(first”);
vct.add(第二”);
vct.add(第三”);
vct.add(第四”);
枚举<字符串> enm = vct.elements();
while(enm.hasMoreElements()){
System.out.println(enm.nextElement());
}
}
}
first
second
third
fourth