Map<String,String> map =new HashMap<String,String>(); String key,value; for(int i=1;i<=num;i ){ key = "" i; value="value" i; map.put(key,value); }
Map<String,String> map = new HashMap<String,String>(); String key,value; for(int i=1;i<=num;i ){ key="" (i*50); value="value" key; map.put(key,value); }
long startTime1 =System.currentTimeMillis(); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()){ key=iter.next(); value=map.get(key); } long endTime1 =System.currentTimeMillis(); System.out.println("第一个程序运行时间:" (endTime1-startTime1) "ms");
long startTime2 =System.currentTimeMillis(); for(String key2:map.keySet()){ value=map.get(key2); } long endTime2 =System.currentTimeMillis(); System.out.println("第二个程序运行时间:" (endTime2-startTime2) "ms");
long startTime3=System.currentTimeMillis(); Iterator<Map.Entry<String,String>> iter3 =map.entrySet().iterator(); Map.Entry<String,String> entry3; while (iter3.hasNext()){ entry3 = iter3.next(); key = entry3.getKey(); value=entry3.getValue(); } long endTime3 =System.currentTimeMillis(); System.out.println("第三个程序运行时间:" (endTime3-startTime3) "ms");
long startTime4=System.currentTimeMillis(); for(Map.Entry<String,String> entry4:map.entrySet()){ key=entry4.getKey(); value=entry4.getValue(); } long endTime4 =System.currentTimeMillis(); System.out.println("第四个程序运行时间:" (endTime4-startTime4) "ms");
long startTime1 =System.currentTimeMillis(); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()){ key=iter.next(); } long endTime1 =System.currentTimeMillis(); System.out.println("第一个程序运行时间:" (endTime1-startTime1) "ms");
long startTime2 =System.currentTimeMillis(); for(String key2:map.keySet()){ } long endTime2 =System.currentTimeMillis(); System.out.println("第二个程序运行时间:" (endTime2-startTime2) "ms");
long startTime3=System.currentTimeMillis(); Iterator<Map.Entry<String,String>> iter3 =map.entrySet().iterator(); Map.Entry<String,String> entry3; while (iter3.hasNext()){ key = iter3.next().getKey(); } long endTime3 =System.currentTimeMillis(); System.out.println("第三个程序运行时间:" (endTime3-startTime3) "ms");
long startTime4=System.currentTimeMillis(); for(Map.Entry<String,String> entry4:map.entrySet()){ key=entry4.getKey(); } long endTime4 =System.currentTimeMillis(); System.out.println("第四个程序运行时间:" (endTime4-startTime4) "ms");
long startTime1 =System.currentTimeMillis(); Iterator<String> iter = map.keySet().iterator(); while (iter.hasNext()){ value=map.get(iter.next()); } long endTime1 =System.currentTimeMillis(); System.out.println("第一个程序运行时间:" (endTime1-startTime1) "ms");
long startTime2 =System.currentTimeMillis(); for(String key2:map.keySet()){ value=map.get(key2); } long endTime2 =System.currentTimeMillis(); System.out.println("第二个程序运行时间:" (endTime2-startTime2) "ms");
long startTime3=System.currentTimeMillis(); Iterator<Map.Entry<String,String>> iter3 =map.entrySet().iterator(); Map.Entry<String,String> entry3; while (iter3.hasNext()){ value=iter3.next().getValue(); } long endTime3 =System.currentTimeMillis(); System.out.println("第三个程序运行时间:" (endTime3-startTime3) "ms");
long startTime4=System.currentTimeMillis(); for(Map.Entry<String,String> entry4:map.entrySet()){ value=entry4.getValue(); } long endTime4 =System.currentTimeMillis(); System.out.println("第四个程序运行时间:" (endTime4-startTime4) "ms");
long startTime5=System.currentTimeMillis(); Iterator<String> iter5=map.values().iterator(); while (iter5.hasNext()){ value=iter5.next(); } long endTime5 =System.currentTimeMillis(); System.out.println("第五个程序运行时间:" (endTime5-startTime5) "ms");
long startTime6=System.currentTimeMillis(); for(String value6:map.values()){ } long endTime6 =System.currentTimeMillis(); System.out.println("第六个程序运行时间:" (endTime6-startTime6) "ms");
</h4> 来源:blog.csdn.net/zhangsify/article/details/52966094 END 十期推荐 【261期】面试官:说出几个你熟悉的 Zookeeper 命令 【262期】面试官:谈谈MySQL主从复制的原理 【263期】面试最后一问:你有什么要问我的吗? 【264期】盘点MySQL主从复制,在面试中能被问什么? 【265期】面试官:为什么Integer用==比较时127相等而128不相等? 【266期】面试官:Redis主从集群切换数据丢失问题如何应对? 【267期】10道经典MySQL面试题 【268期】美团面试题:当你的JVM 堆内存溢出后,其他线程是否可继续工作? 【269期】链表高频面试题(包括反转、合并、相交、分割、环长等) 【270期】面试官:Spring的Bean实例化过程应该是怎样的? ? ~