-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentityHashMap2.java
30 lines (26 loc) · 1.08 KB
/
IdentityHashMap2.java
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
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
public class IdentityHashMap2 {
public static void main(String[] args) throws Exception {
Map<String, Integer> map = new HashMap<>();
map.put("a", 1);
map.put(new String("a"), 1);
System.out.println("Map:" + map);
Boolean b = map.put("a", 1).equals(map.put(new String("a"), 1));
System.out.println("b:" + b);
System.out.println("Map:" + map);
System.out.println("Size of Map:" + map.size());
Map<String, Integer> map1 = new IdentityHashMap<>();
map1.put("a", 1);
map1.put(new String("a"), 1);
Boolean c = map1.put("a", 1).equals(map1.put(new String("a"), 1));
System.out.println("c:" + c);
System.out.println("Map1:" + map1);
map1.put(new String("a"), 2);
System.out.println("Map1:" + map1);
map1.put("a", 2);
System.out.println("Map1:" + map1);
System.out.println("Size of Map1:" + map1.size());
}
}