public class HashtableDemo {
static String newLine = System.getProperty("line.separator");
public static void main(String[] args) {
//dictionary can be created using HashTable object
//as dictionary is an abstract class
Hashtable ht = new Hashtable();
//put(key, value)
ht.put("MIKE", 1);
ht.put("CHIN", 2);
ht.put("CHRIS", 3);
ht.put("HOLY", 4);
//looping through all the elements in hashtable
String str;
//you can retrieve all the keys in hashtable using .keys() method
Enumeration names = ht.keys();
while(names.hasMoreElements()) {
//next element retrieves the next element in the dictionary
str = (String) names.nextElement();
//.get(key) returns the value of the key stored in the hashtable
System.out.println(str + ": " + ht.get(str) + newLine);
}
}
}
如何將所有鍵值添加到變量中,如1 + 2 + 3 + 4 = 10?添加散列鍵值
我看不出任何問題... – Smutje
如何可以添加所有關鍵值到一個變量,如1 + 2 + 3 + 4 = 10 – user3314387
檢查Java語言中的「變量」。 – Smutje