HashMap<String, String> emails = new HashMap<String, String>();
//方法一: 用entrySet()
Iterator it = emails.entrySet().iterator();
while(it.hasNext()){
Map.Entry m=(Map.Entry)it.next();
System.out.println("email-" + m.getKey() + ":" + m.getValue());
}
// 方法二:直接再循环中
for (Map.Entry<String, String> m : emails.entrySet())
{
System.out.println("email-" + m.getKey() + ":" + m.getValue());
}
// 方法三:用keySet()
Iterator it = emails.keySet().iterator();
while (it.hasNext()){
String key=(String)it.next();
System.out.println("email-" + key + ":" + emails.get(key));
举出几种 HashMap 的迭代方式
最新推荐文章于 2024-02-14 16:49:07 发布