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 5c54ced

Browse files
committed
iterate-through-a-hashmap
1 parent 5a36139 commit 5c54ced

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ stackoverflow-Java-top-qa
1212
* [Java += 操作符实质](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/java-operator.md)
1313
* [将InputStream转换为String](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/read-convert-an-inputstream-to-a-string.md)
1414
* [将数组转换为List](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/create-arraylist-arraylistt-from-array-t.md)
15+
* [如何遍历map对象](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/iterate-through-a-hashmap.md)
1516

1617
> 代码规范
1718
@@ -31,7 +32,6 @@ stackoverflow-Java-top-qa
3132
- [Proper use cases for Android UserManager.isUserAGoat()?](http://stackoverflow.com/questions/13375357/proper-use-cases-for-android-usermanager-isuseragoat)
3233
- [Differences between HashMap and Hashtable?](http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable)
3334
- [Creating a memory leak with Java [closed]](http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java)
34-
- [Iterate through a HashMap [duplicate]](http://stackoverflow.com/questions/1066589/iterate-through-a-hashmap)
3535
- [Why is char[] preferred over String for passwords?](http://stackoverflow.com/questions/8881291/why-is-char-preferred-over-string-for-passwords)
3636
- [Generating random integers in a range with Java](http://stackoverflow.com/questions/363681/generating-random-integers-in-a-range-with-java)
3737
- [Why is printing "B" dramatically slower than printing "#"?](http://stackoverflow.com/questions/21947452/why-is-printing-b-dramatically-slower-than-printing)

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
##如何遍历map对象(如HashMap)
2+
3+
###jdk1.5以上版本
4+
```java
5+
for (Entry<String, String> entry : map.entrySet()){
6+
System.out.println(entry.getKey() + "/" + entry.getValue());
7+
}
8+
```
9+
需要 import java.util.Map.Entry;
10+
11+
###jdk1.4以下版本
12+
```java
13+
Iterator entries = myMap.entrySet().iterator();
14+
while (entries.hasNext()) {
15+
Entry thisEntry = (Entry) entries.next();
16+
Object key = thisEntry.getKey();
17+
Object value = thisEntry.getValue();
18+
}
19+
```
20+
21+
stackoverflow链接:
22+
http://stackoverflow.com/questions/271526/avoiding-null-statements-in-java?page=2&tab=votes#tab-top

0 commit comments

Comments
(0)

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