Java Utililty Methods Map Copy

List of utility methods to do Map Copy

Description

The list of methods to do Map Copy are organized into topic(s).

Method

Mapcopy(final Map source)
Clones a map.
if (source == null) {
    return null;
final Map<K, V> result = new HashMap<K, V>();
result.putAll(source);
return result;
voidcopy(Map dest, Map src)
copy
for (Object k : src.keySet()) {
    Object v = src.get(k);
    dest.put(k, v);
voidcopy(Map master, Map slave)
copy
slave.clear();
Iterator itr = master.entrySet().iterator();
while (itr.hasNext()) {
    Map.Entry entry = (Map.Entry) itr.next();
    Object key = entry.getKey();
    Object value = entry.getValue();
    slave.put(key, value);
Mapcopy(Map to, Map from, Object keys[])
copy
if (from == null || keys == null)
    return to;
if (to == null)
    to = new HashMap();
for (int i = 0; i < keys.length; i++)
    to.put(keys[i], from.get(keys[i]));
return to;
Mapcopy(Map src, Map propertyRef)
copy
Map<Object, Object> dst = new HashMap<Object, Object>();
Set<?> entrySet = src.entrySet();
for (Object object : entrySet) {
    if (object != null && object instanceof Entry<?, ?>) {
        Entry<?, ?> entry = (Entry<?, ?>) object;
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (key != null) {
...
Map>copy(Map> original)
copy
Map<K, List<E>> copy = new HashMap<K, List<E>>();
for (Entry<K, List<E>> entry : original.entrySet()) {
    copy.put(entry.getKey(), new ArrayList<E>(entry.getValue()));
return copy;
Mapcopy(Map map)
copy
Map<K, V> copy = new HashMap<>();
for (K key : map.keySet()) {
    copy.put(key, map.get(key));
return copy;
voidcopy(Map master, Map copy)
copy
copy.clear();
merge(master, copy);
Map>copy(Map> original)
copy
Map<String, Map<String, String>> copy = new HashMap<>();
if (original != null) {
    for (String key : original.keySet()) {
        copy.put(key, new HashMap<>(original.get(key)));
return copy;
voidcopy(Map src, Map dst)
copy
for (Entry<T, K> e : src.entrySet()) {
    dst.put(e.getKey(), e.getValue());