Iterator> it=stu_map.entrySet().iterator();
while(it.hasNext()){
String id=it.next().getKey();
Student s=it.next().getValue();
System.out.println(id+"姓名:"+s.getName()+",年龄:"+s.getAge());
}
java.util.NoSuchElementException
Map stu_map = new HashMap();
stu_map.put("id","1");
stu_map.put("s","pgy");
Iterator it = stu_map.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,String> stu = (Map.Entry<String, String>) it.next();
String id = stu.getKey();
String s = stu.getValue();
System.out.println(id+"姓名:"+s);
}
我把String id=it.next().getKey();删除之后就能正常,为什么会这样?
http://www.cnblogs.com/dennisac/archive/2012/03/30/2426074.html