Java Map Remove removeKeysWithPrefix(Map map, String prefix)

Here you can find the source of removeKeysWithPrefix(Map map, String prefix)

Description

remove Keys With Prefix

License

Apache License

Declaration

public static void removeKeysWithPrefix(Map<String, Object> map, String prefix) 

Method Source Code

//package com.java2s;
/*/* www .  ja  v  a2  s .c o  m*/
 * Copyright 2012-2015 Red Hat Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */

import java.util.*;

public class Main {
    public static void removeKeysWithPrefix(Map<String, Object> map, String prefix) {
        Iterator<Map.Entry<String, Object>> iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, Object> e = iter.next();
            if (e.getKey().startsWith(prefix)) {
                iter.remove();
            }
        }
    }
}

Related

  1. removeFromMapValues(final Map map, final Object value)
  2. removeGeneric( List> list)
  3. removeHeader(Map headers, String header)
  4. removeKeyAndConvertToListOfMaps( Object obj, String key)
  5. removeKeys(Collection keys, Map map)
  6. removeMapEntryFromPreferenceStoredMap(String keyOfPreference, String keyInMap)
  7. removeNamespaces(Map properties)
  8. removeNode(Map map, List pathItems)
  9. removeNullEntries(Map map)