Java String Remove removeKeyPrefix(Properties properties, String prefix)

Here you can find the source of removeKeyPrefix(Properties properties, String prefix)

Description

Removes entries which have the specified prefix in their key.

License

Apache License

Parameter

Parameter Description
properties target properties
prefix target prefix

Exception

Parameter Description
IllegalArgumentException if any parameter is null

Declaration

public static void removeKeyPrefix(Properties properties, String prefix) 

Method Source Code

//package com.java2s;
/**//from  ww  w . j  av  a2  s  .  c om
 * Copyright 2011-2017 Asakusa Framework Team.
 *
 * 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.Iterator;

import java.util.Properties;

public class Main {
    /**
     * Removes entries which have the specified prefix in their key.
     * @param properties target properties
     * @param prefix target prefix
     * @throws IllegalArgumentException if any parameter is {@code null}
     */
    public static void removeKeyPrefix(Properties properties, String prefix) {
        if (properties == null) {
            throw new IllegalArgumentException("properties must not be null"); //$NON-NLS-1$
        }
        if (prefix == null) {
            throw new IllegalArgumentException("prefix must not be null"); //$NON-NLS-1$
        }
        for (Iterator<?> iter = properties.keySet().iterator(); iter.hasNext();) {
            Object key = iter.next();
            if ((key instanceof String) == false) {
                continue;
            }
            String name = (String) key;
            if (name.startsWith(prefix)) {
                iter.remove();
            }
        }
    }
}

Related

  1. removeFromSearchPath(String _path)
  2. removeGender(String pos)
  3. removeGenericQuote(String str)
  4. removeIllegalXMLChars(String in)
  5. removeImportClass(String className)
  6. removeModuleReference(String allStr, String refStr)
  7. removeNewLineAndTab(String value)
  8. removePostfixedNewline(String s)
  9. removeProperty(String name)