首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

hash地图的使用

2012-09-09 
hashmap的使用import java.util.HashMapimport java.util.Mapimport java.util.Setpublic class MainCl

hashmap的使用
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MainClass {
public static void main(String args[]) {

   HashMap hm = new HashMap();

   hm.put("A", new Double(3434.34));
   hm.put("B", new Double(123.22));
   hm.put("C", new Double(1378.00));
   hm.put("D", new Double(99.22));
   hm.put("E", new Double(-19.08));

   Set> set = hm.entrySet();

   for (Map.Entry me : set) {
     System.out.print(me.getKey() + ": ");
     System.out.println(me.getValue());
   }

   System.out.println();

   double balance = hm.get("B");
   hm.put("B", balance + 1000);

   System.out.println("B's new balance: " + hm.get("B"));
}
}

热点排行