Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Main { public static <V> Map<String, V> cleanupMap(Map<String, V> map) { if (map == null || map.isEmpty()) { return null; } Map<String, V> result = new HashMap<String, V>(map.size()); Set<Entry<String, V>> entries = map.entrySet(); for (Entry<String, V> entry : entries) { if (entry.getValue() != null) { result.put(entry.getKey(), entry.getValue()); } } return result; } }