Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { /** * Removes any keys not found in the element collection provided in this method * @param map * @param keysToKeep * @return */ public static <K, V> Map<K, V> filterKeys(Map<K, V> map, K... keysToKeep) { Map<K, V> filteredMap = new HashMap<K, V>(); for (K key : keysToKeep) { if (map.containsKey(key)) { filteredMap.put(key, map.get(key)); } } return filteredMap; } }