作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
当我们有 for lop 那么为什么我们使用迭代器下面的代码是一些作为迭代器给出的结果工作
public class HashMapExample {
public static void main(String[] args) {
HashMap<String, String> hasmap = new HashMap<String, String>();
hasmap.put("1", "Java");
hasmap.put("2", ".Net");
hasmap.put("3", "C++");
hasmap.put("4", "Pearl");
hasmap.put("5", "PHP");
for (Entry<String, String> entry : hasmap.entrySet()) {
System.out.println("For Loop Get Key"+entry.getKey());
System.out.println("For Loop Get Value"+entry.getValue());
}
Set set = hasmap.entrySet();
Iterator itr = set.iterator();
while(itr.hasNext()){
Map.Entry map = (Entry) itr.next();
System.out.println(map.getKey());
System.out.println(map.getValue());
}
}
}
我是一名优秀的程序员,十分优秀!