将条目从一个映射复制到另一个映射,并删除目标映射中源映射中的值为空的条目。
//package com.nowjava;/** 来自 时 代 J a v a - nowjava.com**/ import java.util.Map; public class Main { /** * Copies entries from one map to another and deletes those entries in the target map for which * the value in the source map is null.<p> * * @param <A> the key type of the map * @param <B> the value type of the map * @param source the source map * @param target the target map */ public static <A, B> void updateMapAndRemoveNulls(Map<A, B> source, Map<A, B> target) { assert source != target; for (Map.Entry<A, B> entry : source.entrySet()) { A key = entry.getKey(); B value = entry.getValue(); if (value != n