★☆

★☆
posts - 0, comments - 0, trackbacks - 0, articles - 80
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

HashMap的使用

Posted on 2008-08-13 12:51 阅读(207) 评论(0)  编辑  收藏 所属分类: J2SM
HashMap的使用:

//HashMap的使用
private HashMap<String,Object> mapDegree;      //放入Degree的数据

public static void main(String[] args) {
 HashMapTest a = new HashMapTest();
 a.hashMap();
 a.hashMapTest("0001");
 a.hashMapTest("0002");
 a.hashMapTest("0003");
 a.hashMapTest("000");
}
 public void hashMap()
 {
 String [] degree = {"123","456","aaa"};
 mapDegree = new HashMap<String,Object>();//初始化
 //添加数据
 mapDegree.put("0001", degree[0]); 
 mapDegree.put("0002", degree[1]);
 mapDegree.put("0003", degree[2]);
 }
 //通过key取得所对应的值
public void hashMapTest(String key)
 {
  if(mapDegree.get(key)==null){
  System.out.println(key);
  }
  if(mapDegree.get(key)!=null){
  System.out.println(mapDegree.get(key));
  }
}