Java Map Remove removeEmptyValues(Map params)

Here you can find the source of removeEmptyValues(Map params)

Description

Strip all entries from params whose value is either null or the empty string.

License

Open Source License

Parameter

Parameter Description
params The map to strip empty values from.

Return

Returns the params map itself.

Declaration

public static Map<String, String> removeEmptyValues(Map<String, String> params) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.Map;

public class Main {
    /**//ww w.  j a v  a 2  s . co  m
     * Strip all entries from <tt>params</tt> whose value is either
     * <tt>null</tt> or the empty string.
     * @param params The map to strip empty values from.
     * @return Returns the <tt>params</tt> map itself.
     */
    public static Map<String, String> removeEmptyValues(Map<String, String> params) {
        for (Iterator<Map.Entry<String, String>> iter = params.entrySet().iterator(); iter.hasNext();) {
            Map.Entry<String, String> entry = iter.next();
            if (null == entry.getValue() || "".equals(entry.getValue())) {
                iter.remove();
            }
        }
        return params;
    }
}

Related

  1. removeColor(Map windowColorCountMap, int windowColorCount, int lastColor)
  2. removeDefaultAnnotationPackage(final String packageName, final Map context)
  3. removeDoubleQuotes(Map argMap)
  4. removeElementFromJsonMap(Map toscaJson, String elementName)
  5. removeEmptyArray(Map map)
  6. removeExistingItemsFromProvided(Map existingItems, Map providedItems)
  7. removeFrom(Map map, K key)
  8. removeFromMap( Map map, K key, V value)
  9. removeFromMapValues(final Map map, final Object value)