用iterator的hasnext()遍历map,只能遍历一次?怎样再从头遍历一次啊? 再来一次,也不失为一个解决办法! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HashMap h = new HashMap(); h.put("1","1aaaa"); h.put("2","2222"); Iterator it = h.keySet().iterator(); while(it.hasNext()){ Object obj = it.next(); System.out.println(obj + ": "+h.get(obj)); } System.out.println("=============================="); it = h.keySet().iterator(); while(it.hasNext()){ Object obj = it.next(); System.out.println(obj + ": "+h.get(obj)); } 这样就好需要注意的是如果多线程访问这个HashMap,并且可能有修改,就需要sychronize(h{) it = h.keySet().iterator(); while(it.hasNext()){ Object obj = it.next(); System.out.println(obj + ": "+h.get(obj)); } 求高手指教 新手问题。来看下。 java 里的冒号是什么意思 JSP中rs.getString ()的换行问题 悬浮菜单及树问题 如何判断一个文件夹下是否有子文件夹? WebLogic Server 国际化 一个网袋布局(GridBagLayout)的问题 JB8连接09i的问题...提示:Io 异常: The Network Adapter could not establish the connection 有没有把JAVA程序转到C的工具? 怎么修改类似Integer,Short,Long等等的类的对象的值? 如何将一个文本文件的内容读取到一个字符串里?
h.put("1","1aaaa");
h.put("2","2222");
Iterator it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
}
System.out.println("==============================");
it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
} 这样就好需要注意的是如果多线程访问这个HashMap,并且可能有修改,就需要
sychronize(h{)
it = h.keySet().iterator();
while(it.hasNext()){
Object obj = it.next();
System.out.println(obj + ": "+h.get(obj));
}