以下实例演示了如何使用 enumeration 类的 hasmoreelements 和 nestelement 方法来遍历输出 hashtable 中的内容:
/*
author by w3cschool.cc
main.java
*/
import java.util.enumeration;
import java.util.hashtable;
public class main {
public static void main(string[] args) {
hashtable ht = new hashtable();
ht.put("1", "one");
ht.put("2", "two");
ht.put("3", "three");
enumeration e = ht.elements();
while(e.hasmoreelements()){
system.out.println(e.nextelement());
}
}
}
以上代码运行输出结果为:
three
two
one
以上就是java 实例 - 使用 enumeration 遍历 hashtable的内容。