-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashTableDemo.java
35 lines (28 loc) · 1.05 KB
/
HashTableDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Enumeration;
import java.util.Hashtable;
class HashTableDemo {
public static void main(String args[]) {
Hashtable<String, Double> balance = new Hashtable<>();
String str;
double bal;
balance.put("John Doe", 3434.34);
balance.put("Tom Smith", 123.22);
//balance.put("Jane Baker", null); // error
//balance.put(null, new Double(0)); // error
balance.put("Jane Baker", 1378.00);
balance.put("Tod Hall", 99.22);
balance.put("Ralph Smith", -19.08);
// get iterator
Enumeration<String> itr = balance.keys();
while (itr.hasMoreElements()) {
str = itr.nextElement();
System.out.println(str + ": " + balance.get(str));
}
System.out.println();
String key = "John Doe";
// Deposit 1,000 into John Doe's account
bal = balance.get(key);
balance.put(key, bal + 1000);
System.out.println(key + "'s new balance: " + balance.get(key));
}
}