测试用的一个public class HashMapTest { private static Map temp = new HashMap(); 
 
 public static void main(String[] args) {
  for(int i=0; i<10; i++){
   String str = "string" + i;
   temp.put(new Integer(i), str);
  }
  for(Iterator it = temp.entrySet().iterator(); it.hasNext(); ){
   Map.Entry e = (Map.Entry)it.next();
   System.out.println("key: " + e.getKey());
   System.out.println("value: " + e.getValue());
  }
 }
}

解决方案 »

  1.   

    键和值迭代器到底干什么用? 
    因为键是一个集合, 值是一个集全,所以你可以把他们看成list或者set, 所以他们也是有迭代器方法
      

  2.   

    通过键取值啊,
    你可以理解成一个索引,通过key你会很快的找到你需要的值
      

  3.   

    在问大家一个问题
    Map<String, String>books = new HashMap<String, String>();
    这里的泛型<String,String>
    这个是什么含义
    用一个泛型<String,String>这个我明白
    用2个是?????
      

  4.   

    这个的意思是  Map中的key(键)是String类型的,然后值也是String类型的,意思就是这个Map中的键值都是String类型的!
      

  5.   

    1.迭代器就是遍历容器用的,跟键值对没啥关系,
    你这例子中的意思是分别将Map中的所有key值和value值取出来,
    (Map的keySet() 与values()方法的返回值分别为Set,Collection容器引用的对象)
    然后用迭代器遍历的方式将得到的容器里的值一个一个显示出来而已
    建议多查查JDK!
    2.引用和实际对象的泛型得统一,所以要用两个。
      

  6.   

    Map <String, String>books = new HashMap <String, String>(); 
    map包含一个键集合和值集合
    分别可以迭代
    一个键又对应一个值
      

  7.   

    Map <String, String,String>books = new HashMap <String, String,String>(); 
    要是3个呢????
    这样可以吗?
      

  8.   

    遍历就是把所有的值循环读出来
    http://blog.csdn.net/carefree31441