Java Map Copy copyExcludingKeys(Map map, Set excludedKeys)

Here you can find the source of copyExcludingKeys(Map map, Set excludedKeys)

Description

Returns new Map

License

Open Source License

Parameter

Parameter Description
map a parameter
excludedKeys a parameter

Declaration

public static <K, V> Map<K, V> copyExcludingKeys(Map<K, V> map, Set<K> excludedKeys) 

Method Source Code

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

import java.util.HashMap;

import java.util.Map;
import java.util.Map.Entry;

import java.util.Set;

public class Main {
    /**//from  w  w w. j  a v a 2s.  co  m
     * Returns new Map
     *
     * @param map
     * @param excludedKeys
     * @return
     */
    public static <K, V> Map<K, V> copyExcludingKeys(Map<K, V> map, Set<K> excludedKeys) {
        Map<K, V> resultMap = new HashMap<>();
        for (Entry<K, V> entry : map.entrySet()) {
            if (false == excludedKeys.contains(entry.getKey())) {
                resultMap.put(entry.getKey(), entry.getValue());
            }
        }
        return resultMap;
    }
}

Related

  1. copy(Map> original)
  2. copy(Map src, Map dst)
  3. copyAndRemove(Map map, K key)
  4. copyDeep(Map> data)
  5. copyEntries(Map aSource, Map aTarget)
  6. copyHashMap(HashMap map1, HashMap map2)
  7. copyLowerCaseMap(Map map)
  8. copyMap(Map from, Map to)
  9. copyMap(Map sourceMap, Map targetMap)