Java.util.Dictionary.elements() 方法
描述
java.util.Dictionary.elements() 方法返回此字典中的值的枚举。
声明
以下是 java.util.Dictionary.elements() 方法的声明
public abstract Enumeration<V> elements()
参数
NA
返回值
此方法返回此字典中值的枚举。
异常
NA
示例
下面的例子展示了 java.util.Dictionary.elements() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class DictionaryDemo {
public static void main(String[] args) {
// create a new hashtable
Dictionary d = new Hashtable();
// add 2 elements
d.put(1, "Cocoa");
d.put(4, "Chocolate" + "Bar");
System.out.println("\"1\" is " + d.get(1));
System.out.println("\"4\" is " + d.get(4));
// generates a series of elements, one at a time
for (Enumeration e = d.elements(); e.hasMoreElements();) {
System.out.println(e.nextElement());
}
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
"1" is Cocoa "4" is ChocolateBar ChocolateBar Cocoa

