当前位置: 代码迷 >> Java Web开发 >> 求好心人,帮菜鸟看看这个HashMap为什么打印不出来呢
  详细解决方案

求好心人,帮菜鸟看看这个HashMap为什么打印不出来呢

热度:36   发布时间:2016-04-17 16:20:12.0
求好心人,帮初学者看看这个HashMap为什么打印不出来呢
package   s;

import   java.util.Collection;
import   java.util.HashMap;
import   java.util.Iterator;
import   java.util.Map;
import   java.util.Set;

public   class   HashMapTest   {
  public   static   void   printElements(Collection   c)
  {
  Iterator   it=c.iterator();
  while(it.hasNext())
  {
  System.out.println(it.next());
  }
  }
  public   static   void   main(String[]   args)
  {
  HashMap <Object,Object>   hm=new   HashMap <Object,Object> ();
  hm.put( "one ", "zhangsan ");
  hm.put( "two ", "lisi ");
  hm.put( "three ", "wangwu ");
 
 
 
  Set   entry=hm.entrySet();
  //printElements(entry);
  Iterator   it=entry.iterator();
  while(it.hasNext());
  {
  Map.Entry   me=(Map.Entry)it.next();
  System.out.println(me.getKey()+ ": "+me.getValue());
  }
  }
}

 


------解决方案--------------------
你的while循环
while(it.hasNext());
{
Map.Entry me=(Map.Entry)it.next();
System.out.println(me.getKey()+ ": "+me.getValue());
}
那“while(it.hasNext());”后面多了个分号

  相关解决方案