forked from andyczy/czy-study-java-commons-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleMap.java
More file actions
34 lines (29 loc) · 875 Bytes
/
ExampleMap.java
File metadata and controls
34 lines (29 loc) · 875 Bytes
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
package lambda;
import java.util.HashMap;
import java.util.Map;
/**
* @Auther 陈郑游
* @Data 2017/8/21 0021
* @Description:
* @CSDN:http://blog.csdn.net/javawebrookie
* @GITHUB:https://github.com/AndyCZY
*/
public class ExampleMap {
private static Map<String, Integer> items = new HashMap<>();
static {
items.put("A", 10);
items.put("B", 20);
items.put("C", 30);
items.put("D", 40);
items.put("E", 50);
items.put("F", 60);
}
public static void main(String[] args) {
//Java8之前遍历是这样遍历map
for(Map.Entry<String,Integer> entry:items.entrySet()){
System.out.println("key:" + entry.getKey() + " value:" + entry.getValue());
}
//Java8遍历map
items.forEach((key,value)-> System.out.println("key:" + key + " value:" + value));
}
}