sub Tree from Properties - Java java.util

Java examples for java.util:Properties File

Description

sub Tree from Properties

Demo Code


//package com.java2s;
import java.util.Properties;

public class Main {
    public static Properties subTree(Properties props, String prefix,
            String newPrefix) {/*from w ww. ja  v  a2 s.c  o  m*/
        prefix = prefix + ".";
        if (newPrefix != null)
            newPrefix = newPrefix + ".";
        else
            newPrefix = "";
        Properties ret = new Properties();
        for (String i : props.stringPropertyNames()) {
            if (!i.startsWith(prefix))
                continue;
            String suffix = i.substring(prefix.length());
            ret.put(newPrefix + suffix, props.get(i));
        }
        return ret;
    }
}

Related Tutorials