爱问知识人 爱问教育 医院库

HashMap基本用法

首页

HashMap基本用法

IT技术

提交回答
好评回答
  • 2012-11-10 19:37:09
    HashMap是java的常用的容器,它按照KEY=VALUE格式保存数据
    使用起来非常简单,使用put(key,value)将数据保存在map中
    使用get(key)获取对应的值,如果没有返回NULL
    如果要遍历所有的值,首先使用keySet获取全部的key的集合,然后获取key集合的迭代,使用迭代遍历全部的key就行了

    好***

    2012-11-10 19:37:09

其他答案

    2012-11-22 07:35:55
  •   一个很简单的例子。
    
    import java。util。*;
    class HashMapDemo {
    public static void main(String args[]) {
    //生成一个HashMap
    HashMap hm = new HashMap();
    // 把元素加到HashMap里面
    hm。
      put("John Doe", new Double(3434。34)); hm。put("Tom Smith", new Double(123。22)); hm。put("Jane Baker", new Double(1378。00)); hm。
      put("Todd Hall", new Double(99。22)); hm。put("Ralph Smith", new Double(-19。08)); // 从HashMap 里面取出一个集合。 Set set = hm。entrySet(); // 生成一个迭代 Iterator i = erator(); // 显示刚才放进去的东西。
       while(i。hasNext()) { Map。Entry me = (Map。Entry) xt(); int( tKey() + ": "); intln( tValue()); } intln(); // 再放1000到John Doe的帐户里面。
       double balance = ((Double) t("John Doe"))。doubleValue(); hm。put("John Doe", new Double(balance + 1000)); // 再看看结果。 intln("John Doe's new balance: " + t("John Doe")); } } 。
      

    x***

    2012-11-22 07:35:55

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 177-196
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):