fork download
  1. import java.util.*;
  2.  
  3. public class HashMapDemo {
  4.  
  5. public static void main(String args[]) {
  6. // Create a hash map
  7. HashMap hm = new HashMap();
  8. // Put elements to the map
  9. hm.put("Zara", new Double(3434.34));
  10. hm.put("Mahnaz", new Double(123.22));
  11. hm.put("Ayan", new Double(1378.00));
  12. hm.put("Daisy", new Double(99.22));
  13. hm.put("Qadir", new Double(-19.08));
  14.  
  15. // Get a set of the entries
  16. Set set = hm.entrySet();
  17. // Get an iterator
  18. Iterator i = set.iterator();
  19. // Display elements
  20. while(i.hasNext()) {
  21. Map.Entry me = (Map.Entry)i.next();
  22. System.out.print(me.getKey() + ": ");
  23. System.out.println(me.getValue());
  24. }
  25. System.out.println();
  26. // Deposit 1000 into Zara's account
  27. double balance = ((Double)hm.get("Zara")).doubleValue();
  28. hm.put("Zara", new Double(balance + 1000));
  29. System.out.println("Zara's new balance: " +
  30. hm.get("Zara"));
  31. }
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class HashMapDemo is public, should be declared in a file named HashMapDemo.java
public class HashMapDemo {
       ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
stdout
Standard output is empty