Java Map Copy copyMapWithoutEmpties(Map original)

Here you can find the source of copyMapWithoutEmpties(Map original)

Description

copy Map Without Empties

License

Open Source License

Declaration

public static Map<Object, Object> copyMapWithoutEmpties(Map<? extends Object, ? extends Object> original) 

Method Source Code


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

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

public class Main {
    public static Map<Object, Object> copyMapWithoutEmpties(Map<? extends Object, ? extends Object> original) {
        Map<Object, Object> result = new HashMap<Object, Object>();

        Set<?> keys = original.keySet();
        for (Object key : keys) {
            Object value = original.get(key);
            if (value == null || value.toString().length() < 1)
                continue;

            result.put(key, value);//  ww  w.j a  va 2 s .c om
        }

        return result;
    }
}

Related

  1. copyMap(Map oMap)
  2. copyMap(Map map)
  3. copyMap(Map m)
  4. copyMap(Object object)
  5. copyMapButFailOnNull(Map entries)
  6. copyOf( Map> map)
  7. copyOf(final Map map)
  8. copyOf(Map src)
  9. copyOnWritePut(K k, V v, Map source)