public void CloneTestMap() {
// testMap
HashMap<String, Object> testMap = new HashMap<String, Object>();
testMap.put("name", "mynameSt");
testMap.put("hp", "01012345678");
testMap.put("age", "23");
testMap.put("height", "179");
System.out.println("testMap: "+ testMap.toString());
System.out.println("===========");
// putAll을 이용
HashMap<String, Object> putAllMap = new HashMap<String, Object>();
putAllMap.putAll(testMap);
System.out.println("putAllMap: "+ putAllMap.toString());
// entrySet을 이용
HashMap<String, Object> entryMap = new HashMap<String, Object>();
for (HashMap.Entry<String, Object> entry : testMap.entrySet()) {
entryMap.put(entry.getKey(), entry.getValue());
}
System.out.println("entryMap: "+ entryMap.toString());
// testMap 조작
testMap.remove("age");
System.out.println("===========");
System.out.println("testMap: "+ testMap.toString());
System.out.println("putAllMap: "+ putAllMap.toString());
System.out.println("entryMap: "+ entryMap.toString());
}
출력
testMap: {name=mynameSt, hp=01012345678, age=23, height=179}
===========
putAllMap: {name=mynameSt, hp=01012345678, age=23, height=179}
entryMap: {name=mynameSt, hp=01012345678, age=23, height=179}
===========
testMap: {name=mynameSt, hp=01012345678, height=179}
putAllMap: {name=mynameSt, hp=01012345678, age=23, height=179}
entryMap: {name=mynameSt, hp=01012345678, age=23, height=179}