Hashtable: keySet()
/**
*Output:
A: 4.34
E: -9.08
D: 9.22
C: 8.0
B: 3.22
A's new balance: 1004.34
*/
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
public class MainClass {
public static void main(String args[]) {
Hashtable<String, Double> balance = new Hashtable<String, Double>();
String str;
double bal;
balance.put("A", 4.34);
balance.put("B", 3.22);
balance.put("C", 8.00);
balance.put("D", 9.22);
balance.put("E", -9.08);
Set<String> set = balance.keySet();
Iterator<String> itr = set.iterator();
while (itr.hasNext()) {
str = itr.next();
System.out.println(str + ": " + balance.get(str));
}
System.out.println();
bal = balance.get("A");
balance.put("A", bal + 1000);
System.out.println("A's new balance: " + balance.get("A"));
}
}
Related examples in the same category