class Main{
public static void main(String[] args) {
Map<Integer,Integer>map=new HashMap<>();
for (int i = 0; i <10000 ; i++) {
map.put(i,i);
}
//方法一:
long begin1=System.currentTimeMillis();
for(Map.Entry<Integer,Integer>p:map.entrySet()){
System.out.println(p.getValue()+" "+p.getKey());
}
long end1=System.currentTimeMillis()
方法二:
long begin2=System.currentTimeMillis();
Set en=map.entrySet();
Iterator i=en.iterator();
while(i.hasNext()){
Map.Entry e=(Map.Entry)(i.next());
System.out.println(e.getKey()+" "+e.getValue());
}
long end2=System.currentTimeMillis();
方法三:
long begin3=System.currentTimeMillis();
Iterator<Integer>iterator=map.keySet().iterator();
while(iterator.hasNext()){
int oo=iterator.next();
System.out.println(oo+" "+map.get(oo));
}
long end3=System.currentTimeMillis();
//输出三个的时间比较
System.out.println(end1-begin1);
System.out.println(end2-begin2);
System.out.println(end3-begin3);
}
}