Java HashMap Copy copyItem(HashMap to, HashMap from, String key)

Here you can find the source of copyItem(HashMap to, HashMap from, String key)

Description

copy item from one map to another map

License

Open Source License

Parameter

Parameter Description
to the map which data will be copied to
from the map which data will be copied from
key the key name which will be copied

Declaration

public static void copyItem(HashMap to, HashMap from, String key) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

public class Main {
    /**/*www .j  a v  a 2 s . c o m*/
     * copy item from one map to another map
     *
     * @param to the map which data will be copied to
     * @param from the map which data will be copied from
     * @param key the key name which will be copied
     *
     */
    public static void copyItem(HashMap to, HashMap from, String key) {
        copyItem(to, from, key, key, false);
    }

    /**
     * copy item from one map to another map original data might be delete based
     * on last boolean value
     *
     * @param to the map which data will be copied to
     * @param from the map which data will be copied from
     * @param key the key name which will be copied
     * @param deleteFlg decide if delete the original data(true for delete)
     *
     */
    public static void copyItem(HashMap to, HashMap from, String key, boolean deleteFlg) {
        copyItem(to, from, key, key, deleteFlg);
    }

    /**
     * copy item from one map to another map by using different key original
     * data might be delete based on last boolean value
     *
     * @param to the map which data will be copied to
     * @param from the map which data will be copied from
     * @param toKey the key name used in target holder
     * @param fromKey the key name used in original holder
     * @param deleteFlg decide if delete the original data(true for delete)
     *
     */
    public static void copyItem(HashMap to, HashMap from, String toKey, String fromKey, boolean deleteFlg) {
        if (from.get(fromKey) != null) {
            if (deleteFlg && from.get(fromKey) != null) {
                to.put(toKey, from.remove(fromKey));
            } else {
                to.put(toKey, from.get(fromKey));
            }
        }
    }
}

Related

  1. copy(HashMap oldHashMap)
  2. copyDirective(HashMap directives, StringBuilder sb, String directive)
  3. copyHashMap(final HashMap map)
  4. copyHashWords(HashMap> ohwords, HashMap> nhwords, int start, int end, int nstart)
  5. copyMap(HashMap map)
  6. copyParam(HashMap from, HashMap to, String key)