Skip to content

Commit 02c9638

Browse files
Add files via upload
1 parent 001f681 commit 02c9638

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

ConcurrentHashMapMethod_Clone.java

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
import java.util.HashMap;
3+
public class ConcurrentHashMapMethod_Clone {
4+
//Clone
5+
public static void main(String[] args) {
6+
7+
HashMap<String, String> map1 = new HashMap<>();
8+
map1.put("1", "one");
9+
map1.put("2", "two");
10+
map1.put("3", "three");
11+
map1.put("4", "four");
12+
map1.put("5", "five");
13+
map1.put("6", "six");
14+
map1.put("7", "seven");
15+
map1.put("8", "eight");
16+
map1.put("9", "nine");
17+
map1.put("10", "ten");
18+
19+
System.out.println(" ");
20+
HashMap<String, String> map2 = (HashMap<String, String>) map1.clone();
21+
22+
ConcurrentHashMap<String, String> map3 = new ConcurrentHashMap<>(map2);
23+
System.out.println("Map3:" + map3);
24+
System.out.println(" ");
25+
26+
//Create a copy of the Map
27+
28+
ConcurrentHashMap<String, String> map4 = new ConcurrentHashMap<>(map1);
29+
System.out.println("Map4:" + map4);
30+
System.out.println(" ");
31+
32+
33+
}
34+
35+
36+
}
37+
38+
/***
39+
*
40+
* Hence we cannot call directly the Clone method on the ConcurrentHashMap class.
41+
* It belongs to Abstract Map which is not visible to the class.
42+
*
43+
*
44+
*
45+
*/

0 commit comments

Comments
 (0)