Java - How to deep copy HashSet, HashMap

790 ワード

Deep copy HashSet
HashSet set = new HashSet();
HashSet set2 = new HashSet();
set2.addAll(set);

or
HashSet set = new HashSet();
HashSet set2 = new HashSet(set);

Deep copy HashMap
HashMap map = new HashMap<>();
HashMap map2 = new HashMap<>();
map2.putAll(map);

or
HashMap map = new HashMap<>();
HashMap map2 = new HashMap<>(map);

Anyway, Good luck, Richardo! -- 09/27/2016