的元件()方法用来返回此向量的组件的枚举。返回的Enumeration对象将在相似的索引位置生成此向量中的所有项目。
import java.util.Vector; public class VectorDemo { public static void main(String[] args) { Vector<Integer> vec = new Vector<Integer>(4); vec.add(4); vec.add(3); vec.add(2); vec.add(1); Enumeration e=vec.elements(); System.out.println("Numbers in the enumeration are :- "); while (e.hasMoreElements()) { System.out.println("Number = " + e.nextElement()); } } }
输出结果
Numbers in the enumeration are :- Number = 4 Number = 3 Number = 2 Number = 1