rootUser

HASH MAP

Jul 9th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.10 KB | None | 0 0
  1. package hashmap;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Set;
  6.  
  7. public class HASHMAP
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         // Create a hash map.
  12.         HashMap<String, Double> hm = new HashMap<String, Double>();
  13.         // Put elements to the map
  14.         hm.put("John Doe", new Double(3434.34));
  15.         hm.put("Tom Smith", new Double(123.22));
  16.         hm.put("Jane Baker", new Double(1378.00));
  17.         hm.put("Tod Hall", new Double(99.22));
  18.         hm.put("Ralph Smith", new Double(-19.08));
  19.         // Get a set of the entries.
  20.         Set<Map.Entry<String, Double>> set = hm.entrySet();
  21.         // Display the set.
  22.         for(Map.Entry<String, Double> me : set)
  23.         {
  24.             System.out.print(me.getKey() + ": ");
  25.             System.out.println(me.getValue());
  26.         }
  27.         System.out.println();
  28.         // Deposit 1000 into John Doe's account.
  29.         double balance = hm.get("John Doe");
  30.         hm.put("John Doe", balance + 1000);
  31.         System.out.println("John Doe's new balance: " +
  32.         hm.get("John Doe"));
  33.     }
  34.  
  35. }
Add Comment
Please, Sign In to add comment