Entry是Map中的一个内部累,map.entrySet()可以得到key和value的视图给你一个比较简单的小事例
public static void main(String[] args) {
Map map = new HashMap();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
map.put("key4", "value4");
Set set = map.keySet();//将map的kye放到set里了
Iterator iter = set.iterator();
while(iter.hasNext()){
String key = (String)iter.next();
System.out.println("key=" + key + " value=" + map.get(key));
}
System.out.println("----------------------------------------------------");
Iterator iter1 = map.entrySet().iterator();
while(iter1.hasNext()){
Map.Entry me = (Map.Entry)iter1.next();
System.out.println("key=" + me.getKey() + " value=" + me.getValue());
}
}