Hashtable: keySet() : Hashtable : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.util   » [  Hashtable  ]   
 



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: entrySet()
4.  Hashtable: iterator()
5.  Hashtable: put(K key, V value)
6.  Hashtable: get(E e)
7.  Hashtable: keys()
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.