亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

map集合遍歷的三種方式 map怎么遍歷刪除( 二 )


long startTime2 =System.currentTimeMillis();for(String key2:map.keySet()){value=https://www.520longzhigu.com/diannao/map.get(key2);}long endTime2 =System.currentTimeMillis();System.out.println("第二個(gè)程序運(yùn)行時(shí)間:"+(endTime2-startTime2)+"ms");3)entrySet利用Iterator遍歷
long startTime3=System.currentTimeMillis();Iterator<Map.Entry<String,String>> iter3 =map.entrySet().iterator();Map.Entry<String,String> entry3;while (iter3.hasNext()){value=https://www.520longzhigu.com/diannao/iter3.next().getValue();}long endTime3 =System.currentTimeMillis();System.out.println("第三個(gè)程序運(yùn)行時(shí)間:" +(endTime3-startTime3)+"ms");4)entrySet利用for遍歷
long startTime4=System.currentTimeMillis();for(Map.Entry<String,String> entry4:map.entrySet()){value=https://www.520longzhigu.com/diannao/entry4.getValue();}long endTime4 =System.currentTimeMillis();System.out.println("第四個(gè)程序運(yùn)行時(shí)間:"+(endTime4-startTime4) +"ms");5)values利用iterator遍歷
long startTime5=System.currentTimeMillis();Iterator<String>iter5=map.values().iterator();while (iter5.hasNext()){value=https://www.520longzhigu.com/diannao/iter5.next();}long endTime5 =System.currentTimeMillis();System.out.println("第五個(gè)程序運(yùn)行時(shí)間:"+(endTime5-startTime5) +"ms");6)values利用for遍歷
long startTime6=System.currentTimeMillis();for(String value6:map.values()){}long endTime6 =System.currentTimeMillis();System.out.println("第六個(gè)程序運(yùn)行時(shí)間:"+(endTime6-startTime6) +"ms");4、時(shí)間對(duì)比4.1遍歷key+value4.2遍歷key4.3遍歷value5、總結(jié)從上面的時(shí)間比較來看:
1)map的key采用簡(jiǎn)單形式和復(fù)雜形式時(shí),查找的效率是不同的,簡(jiǎn)單的key值效率更高
2)當(dāng)數(shù)據(jù)量大的時(shí)候,采用entrySet遍歷key+value的效率要高于keySet
3)當(dāng)我們只需要取得value值時(shí),采用values來遍歷效率更高


以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!

「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助: