Hashtable: keySet() : Hashtable « java.util « Java by API






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

1.new Hashtable()
2.new Hashtable < K, V > ()
3.Hashtable: clear()
4.Hashtable: clone()
5.Hashtable: contains(Object value)
6.Hashtable: containsKey(Object key)
7.Hashtable: elements()
8.Hashtable: entrySet()
9.Hashtable: get(E e)
10.Hashtable: isEmpty()
11.Hashtable: iterator()
12.Hashtable: keys()
13.Hashtable: put(K key, V value)
14.Hashtable: putAll(Map t)
15.Hashtable: remove(Object key)
16.Hashtable: size()
17.Hashtable: values()