遍历hashmap的两种方法及分析
来源:互联网 发布:职业性格测试软件 编辑:程序博客网 时间:2024/05/02 10:48
遍历hashmap的两种方法及分析
第一种:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
效率高,以后一定要使用此种方式!
第二种:
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
效率低,以后尽量少使用!
HashMap的遍历有两种常用的方法,那就是使用keyset及entryset来进行遍历,但两者的遍历速度是有差别的,
对于keySet其实是遍历了2次,一次是转为iterator,一次就从hashmap中取出key所对于的value。而entryset只是遍历了第一次,他把key和value都放到了entry中,所以就快了。
第一种:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
效率高,以后一定要使用此种方式!
第二种:
Map map = new HashMap();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Object key = iter.next();
Object val = map.get(key);
}
效率低,以后尽量少使用!
HashMap的遍历有两种常用的方法,那就是使用keyset及entryset来进行遍历,但两者的遍历速度是有差别的,
对于keySet其实是遍历了2次,一次是转为iterator,一次就从hashmap中取出key所对于的value。而entryset只是遍历了第一次,他把key和value都放到了entry中,所以就快了。
0 0
- java中遍历hashmap的两种方法及分析
- 【java】遍历hashmap的两种方法及分析
- 遍历hashmap的两种方法及分析
- 【java】遍历hashmap的两种方法及分析
- 遍历hashmap的两种方法及分析
- 【java】遍历hashmap的两种方法及分析
- 遍历HashMap的两种方法及效率
- HashMap的两种遍历方法比较
- 遍历HashMap的两种方法
- 对HashMap的两种遍历方法
- Java: 遍历 HashMap 的两种方法
- Java遍历HashMap的两种方法
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历 .
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- linux日常应用管理(4)
- Oracle DB 配置备份设置
- hdu 1160 FatMouse's Speed(最长上升子序列 +记录路径)
- O2O究竟怎么回事
- apk打包上传Google Play
- 遍历hashmap的两种方法及分析
- STL list
- 数据库模型设计 PowerDesigner
- CSS中expression使用简介
- 安装ubuntu后的配置
- Android pull解析
- vs2010 Release下调试代码设置
- wxwidget pitfall
- 装饰模式与代理模式的区别