Enumeration<E> elements()
描述 (Description)
elements()方法用于返回此向量的组件的枚举。 返回的Enumeration对象将在类似的索引位置生成此向量中的所有项。
声明 (Declaration)
以下是java.util.Vector.elements()方法的声明
public Enumeration<E> elements()
参数 (Parameters)
不带任何输入参数
返回值 (Return Value)
它返回此向量的组件的枚举。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.Vector.elements()方法的用法。
package com.iowiki;
import java.util.Vector;
import java.util.Enumeration;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector<Integer> vec = new Vector<Integer>(4);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// adding elements into the enumeration
Enumeration e = vec.elements();
// let us print all the elements available in enumeration
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