Skip to content

Commit 43cc0cd

Browse files
committed
添加Hashmap代码
1 parent c6cef32 commit 43cc0cd

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
package cn.byhieg.collectiontutorial.maptutorial;
22

3+
import java.util.HashMap;
4+
import java.util.Iterator;
5+
import java.util.Map;
6+
37
/**
48
* Created by shiqifeng on 2017/2/24.
59
* Mail byhieg@gmail.com
610
*/
711
public class HashMapExample {
812

9-
10-
public static void main(String[] args) {
13+
public Map<String, String> insertMap(){
14+
HashMap<String, String> maps = new HashMap<>(10);
15+
for (int i = 0 ; i < 10 ;i++) {
16+
maps.put(i + "", i + "");
17+
}
18+
return maps;
19+
}
1120

1221

22+
public void getValue(Map<? extends String,? extends String> maps,String key) {
23+
System.out.println(maps.get(key));
1324
}
1425

1526

27+
public void getAllKeyAndValue(Map<? extends String, ? extends String> maps) {
28+
Iterator iterator = maps.entrySet().iterator();
29+
while (iterator.hasNext()) {
30+
Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
31+
System.out.println(entry.getKey());
32+
System.out.println(entry.getValue());
33+
}
34+
}
35+
1636
}

0 commit comments

Comments
 (0)