三种遍历map方式的时间比较
来源:互联网 发布:免费房屋设计软件下载 编辑:程序博客网 时间:2024/06/02 05:31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
HashMap<String, String> kmap =
new
HashMap<String, String>();
HashMap<String, String> emap =
new
HashMap<String, String>();
HashMap<String, String> fmap =
new
HashMap<String, String>();
//装数据
for
(
int
i =
0
; i <
1000
; i++)
{
kmap.put(
""
+i,
"YL"
);
}
for
(
int
i =
0
; i <
1000
; i++)
{
emap.put(
""
+i,
"ZT"
);
}
for
(
int
i =
0
; i <
1000
; i++)
{
fmap.put(
""
+i,
"FK"
);
}
long
stimes = System.currentTimeMillis();
long
ctimes = Calendar.getInstance().getTimeInMillis();
long
dtimes =
new
Date().getTime();
//初始时间 这里我用了三种取值方式
System.out.println(stimes+
" "
+ctimes+
" "
+dtimes);
//keySet遍历map
Iterator<String> ktor = kmap.keySet().iterator();
while
(ktor.hasNext())
{
System.out.print(ktor.next() +
"="
+ kmap.get(ktor.next()) +
" "
);
}
long
stimes1 = System.currentTimeMillis();
long
ctimes1 = Calendar.getInstance().getTimeInMillis();
long
dtimes1 =
new
Date().getTime();
System.out.println(stimes1+
" "
+ctimes1+
" "
+dtimes1);
System.out.println((stimes1-stimes)+
" "
+(ctimes1-ctimes)+
" "
+(dtimes1-dtimes));
//entrySet遍历map
Iterator<Entry<String, String>> itor = emap.entrySet().iterator();
while
(itor.hasNext())
{
Entry<String, String> e = itor.next();
System.out.print(e.getKey() +
"="
+ e.getValue() +
" "
);
}
long
stimes2 = System.currentTimeMillis();
long
ctimes2 = Calendar.getInstance().getTimeInMillis();
long
dtimes2 =
new
Date().getTime();
System.out.println(stimes2+
" "
+ctimes2+
" "
+dtimes2);
System.out.println((stimes2-stimes1)+
" "
+(ctimes2-ctimes1)+
" "
+(dtimes2-dtimes1));
//for循环遍历
for
(Map.Entry entry : fmap.entrySet())
{
System.out.print(entry.getKey() +
"="
+ entry.getValue() +
" "
);
}
long
stimes3 = System.currentTimeMillis();
long
ctimes3 = Calendar.getInstance().getTimeInMillis();
long
dtimes3 =
new
Date().getTime();
System.out.println(stimes3+
" "
+ctimes3+
" "
+dtimes3);
System.out.println((stimes3-stimes2)+
" "
+(ctimes3-ctimes2)+
" "
+(dtimes3-dtimes2));
输出结果:
- 三种遍历map方式的时间比较
- 遍历Map的三种方式:
- 遍历Map的三种方式
- 遍历Map的三种方式
- Java Map 的三种遍历方式
- JAVA Map 的三种遍历方式
- JAVA Map 的三种遍历方式
- JAVA Map的三种遍历方式
- 遍历Map的三种方式
- Map集合的三种遍历方式
- map集合,遍历的三种方式
- [javase]遍历Map的三种方式
- Map集合遍历的三种方式
- 遍历map的三种方式
- Java 遍历map 的三种方式
- Map的三种遍历方式
- Map集合遍历的三种方式
- map的三种遍历方式
- Azkaban成功搭建环境的过程
- 基于Linux和QT/E的软键盘设计
- 微信将会成为移动平台入口之一
- ORACLE SQL_TRACE的使用
- iPad版杂志:广告销售增长25% 读者群猛增七成
- 三种遍历map方式的时间比较
- 生成器模式
- JAVA字符串池
- AJAX详解
- C++的精英化趋势与两个关键缺陷
- TIME_WAIT,CLOSE_WAIT
- java内部类的作用分析
- poj 1269 Intersecting Lines
- 一个人一个微博、一个App一个故事:通过微博草根账号做英语学习App的“爱卡微口语”获晨脉创投天使投资