[java]代码库
方法1:
HashMap staff = new HashMap();
Set entries = staff.entrySet();
Iterator iter = entries.iterator();
while(iter.hasNext())
{
Map.Entry entry = (Map.Entry)iter.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
方法2:
Map map = new HashMap();
for(Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next(); //map.entry 同时取出键值对
Object key = entry.getKey();
Object val = entry.getValue();
}
方法3:
Map map = new HashMap();
for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
Object val = map.get(key);
}
方法4:
Set set2 = map.entrySet();
for(Object i:set2)
{
Entry entry = (Entry)i;
System.out.println(entry.getKey()+"--"+entry.getValue());
}