-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMap1.java
More file actions
31 lines (28 loc) · 1006 Bytes
/
Copy pathHashMap1.java
File metadata and controls
31 lines (28 loc) · 1006 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
import java.util.*;
public class HashMap1 {
public static void main(String[] args) {
HashMap<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "aaa");
map.put(2, "aba");
map.put(3, "aab");
map.put(4, "baa");
map.put(5, "bab");
System.out.println("Iterating hashMap : ");
for (Map.Entry m : map.entrySet()) {
System.out.println(m.getKey() + " : " + m.getValue());
}
HashMap<Integer, String> map2 = new HashMap<Integer, String>();
map2.put(6, "hi");
map2.putAll(map);
System.out.println("Iterating other map");
for (Map.Entry m : map2.entrySet()) {
System.out.println(m.getKey() +" : " + m.getValue());
}
map2.remove(4, "baa");
map2.replace(3, "aab", "cena");
System.out.println(map2);
System.out.println("dont knwo : ");
map2.replaceAll((k, v) -> "ashish");
System.out.println(map2);
}
}