返回一个新映射,其中包含输入映射的所有项,但值为空的项除外。
/** from * N o w J a v a . c o m - 时代Java **/ //package com.nowjava; import java.util.HashMap; import java.util.Map; public class Main { /** * Returns a new map with all entries of the input map except those which have a value of null.<p> * * @param <A> the key type of the map * @param <B> the value type of the map * @param map the input map * * @return a map with all null entries removed */ public static <A, B> Map<A, B> removeNullEntries(Map<A, B> map) { HashMap<A, B> result = new HashMap<A, B>(); for (Map.Entry<A, B> entry : map.entrySet()) { if (entry.getValue() != null)