-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapmethods7.java
More file actions
28 lines (21 loc) · 784 Bytes
/
mapmethods7.java
File metadata and controls
28 lines (21 loc) · 784 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
import java.util.HashMap;
public class mapmethods7 {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map.put("One", 1);
map.put("Two", 2);
map.put("Three", 3);
map.put("Four", 4);
map.put("Five", 5);
map.put("Six", 6);
System.out.println("Before clear:" + map);
map.forEach((String key, Integer value) -> {
System.out.println(key + ":" + value);
});
int val = map.getOrDefault("Six", 6);
System.out.println("Value :" + val);
int val1= map.getOrDefault("Six", 7);
System.out.println("Value :" + val1);
System.out.println(map.getOrDefault("Seven", 6));
}
}