怎么会?是不是你的循环写错了?
while(itor.hasNext()){
  Object obj = hashmap.get(itor.next());
}

解决方案 »

  1.   

    import java.util.*;public class HashmapIterator {
      public HashmapIterator() {
      }
      public static void main(String[] args){
        HashMap hm = new HashMap();
        hm.put(new String("name"),new String("author"));
        hm.put(new String("sex"),new String("male"));
        hm.put(new String("city"),new String("beijing"));
        Iterator it = hm.keySet().iterator();
        while(it.hasNext()){
          String key = (String)it.next();
          String value = (String)hm.get(key);
          System.out.println(key + " = " + value);
        }
      }
    }