-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapdemo2.java
More file actions
39 lines (26 loc) · 1014 Bytes
/
Mapdemo2.java
File metadata and controls
39 lines (26 loc) · 1014 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
35
36
37
38
39
package node;
import java.util.HashMap;
import java.util.Map;
public class Mapdemo2 {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map .put("AaaA",1);
map .put("BBBB",2);
map .put("AaBB",3);
map .put("BBAa",4);
map .put("five",5);
map .put("six",6);
map .put("seven",7);
System.out.println(map.keySet());
System.out.println(map.entrySet());
Map<MutableString, String> brokenMap = new HashMap<>();
String value = "abc";
MutableString key = new MutableString(value);
brokenMap.put(key,value);
System.out.println(brokenMap.get(key));
System.out.println(String.valueOf(brokenMap));
key.setValue("def"); // key changed here , pass as a reference, key shouldn't be changed
System.out.println(brokenMap.get(key));
System.out.println(String.valueOf(brokenMap));
}
}