Here you can find the source of copyItem(HashMap to, HashMap from, String key)
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 |
public static void copyItem(HashMap to, HashMap from, String key)
//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)); } } } }