20161031问题解析请点击今日问题下方的“【Java每日一题】20161101”查看(问题解析在公众号首发,公众号ID:weknow619)
package Nov2016;
import java.util.HashMap;
import java.util.Map;
public class Ques1101 {
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
// 遍历1
for (Integer key : map.keySet()) {
Integer value = map.get(key);
System.out.println(key+"---"+value);
}
// 遍历2
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
Integer key = entry.getKey();
Integer value = entry.getValue();
System.out.println(key+"---"+value);
}
}
}
今日问题:请问主程序哪种遍历方法效率更高?(点击以下“【Java每日一题】20161101”查看20161031问题解析)