import java.util.Enumeration;让我们看看编译和执行这段代码是什么样子的:
导入 java.util.Hashtable;
public class putAll_hashtable {
public static void main(String[] s) {
Hashtable table = new Hashtable();
table.put(1”, val1”);
table.put(2”, val2”);
table.put(3”, val3”);
Hashtable table2 = new Hashtable();
table2.put(4”, val4”);
table2.put(5”, val5”);
table2.put(6”, val6”);
table2.putAll(table);
枚举 e = table2.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
System.out.println(key + : ” + table2.get(key));
}
}
}
6 : val6参考:
5 : val5
4 : val4
3 : val3
2 : val2
1: val1
Please disable your ad blocker and refresh the window to use this website.