Here you can find the source of copyValueIfExist(Map
Parameter | Description |
---|---|
K | the key type |
V | the value type |
source | the source map |
target | the target map |
key | the key to copy |
true
if exists and copied
public static <K, V> boolean copyValueIfExist(Map<K, V> source, Map<K, V> target, K key)
//package com.java2s; //License from project: LGPL import java.util.Map; public class Main { /**//w ww.j a va 2 s . com * Copy value from the source map to the target map only if the value exists in the source map. * * @param <K> * the key type * @param <V> * the value type * @param source * the source map * @param target * the target map * @param key * the key to copy * @return <code>true</code> if exists and copied */ public static <K, V> boolean copyValueIfExist(Map<K, V> source, Map<K, V> target, K key) { V v = source.get(key); if (v != null) { target.put(key, v); return true; } return false; } }