Friday, 11 September 2015

HashTable in java util package

import java.util.*;
class HashtableDemo
{ public static void main(String args[])
{ // Create a hash map.
Hashtable<String, Double> ht = new Hashtable<String, Double>();
      // Put elements to the map
ht.put("Devesh",1000.00);
ht.put("Rahul",1500.00);
ht.put("Rakesh",1200.00);
ht.put("Manohar",900.00);
ht.put("Prateek",1300.00);

String name;
Enumeration<String> names = ht.keys();
while(names.hasMoreElements())
{ name = names.nextElement();
System.out.println(name + ": " + ht.get(name));

}
System.out.println();
// Deposit 1000 into Prateek's account.
double balance = (Double) ht.get("Prateek");
ht.put("Prateek", balance + 1000);
balance = (Double)ht.get("Prateek");
System.out.println("Pr ateek's new balance: " + balance);
}
}

No comments:

Post a Comment