fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. //创建一个HashMap对象hm
  13. HashMap hm=new HashMap();
  14. //加入元素到hm中
  15. hm.put("何叶",new Double (213213421.333));
  16. hm.put("张光明",new Double (67231.233));
  17. hm.put("张三",new Double (812371.23));
  18. hm.put("李四",new Double (231231.231));
  19. //返回包含映射中项的集合
  20. Set set=hm.entrySet();
  21. //用Iterator得到HashMap中的内容
  22. Iterator t=set.iterator();
  23. //显示元素
  24. while(t.hasNext())
  25. {
  26. Map.Entry me=(Map.Entry)t.next();
  27. System.out.print(me.getKey()+": ");
  28. System.out.println(me.getValue());
  29. }
  30. System.out.print("\n");
  31. double balance=((Double)hm.get("张光明")).doubleValue();
  32. hm.put("张光明",new Double(balance+89728));
  33. System.out.println("我现在的账户金额:"+hm.get("张光明"));
  34. }
  35. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
李四: 231231.231
张三: 812371.23
何叶: 2.13213421333E8
张光明: 67231.233

我现在的账户金额:156959.233