Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df2d6ac

Browse files
committed
优化"HashMap遍历"
1 parent b362115 commit df2d6ac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎contents/iterate-through-a-hashmap.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HashMap遍历 #
22

3-
在Java中有多种遍历HashMAp的方法。让我们回顾一下最常见的方法和它们各自的优缺点。由于所有的Map都实现了Map接口,所以接下来方法适用于所有Map接口的图的实现(如:HaspMap,TreeMap,LinkedMap,HashTable,etc)
3+
在Java中有多种遍历HashMAp的方法。让我们回顾一下最常见的方法和它们各自的优缺点。由于所有的Map都实现了Map接口,所以接下来方法适用于所有Map(如:HaspMap,TreeMap,LinkedMap,HashTable,etc)
44

55
## 方法#1 使用For-Each迭代entries ##
66

@@ -42,7 +42,7 @@
4242
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
4343
}
4444

45-
不适用泛型
45+
不使用泛型
4646

4747
Map map = new HashMap();
4848
Iterator entries = map.entrySet().iterator();
@@ -71,4 +71,7 @@
7171

7272
## 总结 ##
7373

74-
如果你只需要使用key或者value使用方法#2,如果你坚持使用java的老版本(java 5 以前的版本)或者打算在迭代的时候移除entries使用方法#3,另外的话使用方法#1,尽量避免出现方法#1的情况
74+
如果你只需要使用key或者value使用方法#2,如果你坚持使用java的老版本(java 5 以前的版本)或者打算在迭代的时候移除entries,使用方法#3。其他情况请使用#1方法。避免使用#4方法。
75+
76+
stackoverflow链接:
77+
http://stackoverflow.com/questions/1066589/iterate-through-a-hashmap

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /