[Java] 纯文本查看 复制代码 public class Demo1_MapEntry {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("alex", 27);
map.put("walker", 29);
map.put("jacky", 28);
Set<Map.Entry<String, Integer>> entrySet= map.entrySet();
Iterator<Map.Entry<String, Integer>> it = entrySet.iterator();
while(it.hasNext()) {
Map.Entry<String, Integer> me = it.next(); //父类引用指向子类对象//Entry<String, Integer> me = it.next(); 直接获取的是子类对象
String key = me.getKey();
Integer value = me.getValue();
System.out.println(key + "---" + value);
}
}
}
看视频讲解,Map.Entry是通过子类对象HashMap$Entry来实现的,可是我在Eclipse里面找不到,这是怎么回事?
是不是JDK1.8取消了HashMap$Entry?
|