读书人

HashMap 的两种遍历模式

发布时间: 2012-12-18 12:43:41 作者: rapoo

HashMap 的两种遍历方式

public static void main(String[] args) {Map<String, String> map = new HashMap<String, String>();map.put("a", "b");map.put("b", "b");for(Map.Entry<String, String> entry : map.entrySet()){System.out.println(entry.getKey() + entry.getValue());}Set<Map.Entry<String, String>> set = map.entrySet();Iterator<Map.Entry<String, String>> it = set.iterator();while(it.hasNext()){Map.Entry<String, String> item = it.next();System.out.println(item.getKey() + item.getValue());}}
?

读书人网 >编程

热点推荐