Java Map Remove removeNullValues(final Map parameters)

Here you can find the source of removeNullValues(final Map parameters)

Description

Removes Entries with null as value and returns a new Map

License

Open Source License

Parameter

Parameter Description
parameters a parameter

Return

new map with no null values

Declaration

public static Map<String, String> removeNullValues(final Map<String, String> parameters) 

Method Source Code


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

import java.util.HashMap;
import java.util.Map;

public class Main {
    /**//from  w w w.  j a va  2s  .  c o  m
     * Removes Entries with null as value and returns a new Map
     *
     * @param parameters
     * @return new map with no null values
     */
    public static Map<String, String> removeNullValues(final Map<String, String> parameters) {
        Map<String, String> cleanedParameters = new HashMap<>(parameters.size(), 1);

        for (Map.Entry<String, String> entry : parameters.entrySet()) {
            if (entry.getValue() != null) {
                cleanedParameters.put(entry.getKey(), entry.getValue());
            }
        }

        return cleanedParameters;
    }
}

Related

  1. removeMapEntryFromPreferenceStoredMap(String keyOfPreference, String keyInMap)
  2. removeNamespaces(Map properties)
  3. removeNode(Map map, List pathItems)
  4. removeNullEntries(Map map)
  5. removeNullPair(Map map)
  6. removeNullValues(Map map)
  7. removeObject(Map map, T key)
  8. removeObjectProperty(Map properties, String key, Object defaultValue)
  9. removeOutStringsStrings(Map map, String newString)