forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
31 lines (22 loc) · 1001 Bytes
/
Main.java
File metadata and controls
31 lines (22 loc) · 1001 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
package modern.challenge;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Map<Integer, String> map = new HashMap<>();
map.put(1, "Anna");
map.put(2, "George");
Map<Integer, String> shallowMap1 = Maps.shallowCopyV1(map);
System.out.println("Shallow copy 1: " + shallowMap1);
Map<Integer, String> shallowMap2 = Maps.shallowCopyV2(map);
System.out.println("Shallow copy 2: " + shallowMap2);
List<A> lista = Arrays.asList(new A(1), new A(2));
List<B> listb = Arrays.asList(new B(new A(3), 1), new B(new A(4), 2));
Map<List<A>, List<B>> mapab = new HashMap<>();
mapab.put(lista, listb);
Map<List<A>, List<B>> deepMap = Maps.deepCopy(mapab);
System.out.println("Deep copy: \n" + mapab + " \n" + deepMap);
}
}