Java Utililty Methods Properties

List of utility methods to do Properties

Description

The list of methods to do Properties are organized into topic(s).

Method

PropertiesconvertBundleToProperties(ResourceBundle rb)
Method to convert a ResourceBundle to a Properties object.
Properties props = new Properties();
for (Enumeration<String> keys = rb.getKeys(); keys.hasMoreElements();) {
    String key = keys.nextElement();
    props.put(key, rb.getString(key));
return props;
PropertiesconvertResourceBundleToProperties(ResourceBundle resource)
convert Resource Bundle To Properties
Properties properties = null;
if (resource != null) {
    properties = new Properties();
    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        properties.put(key, resource.getString(key));
return properties;
StringcreateScriptBodyFromScriptSet(Properties scriptSet)
create Script Body From Script Set
StringBuffer sb = new StringBuffer();
for (Enumeration scriptKeys = scriptSet.keys(); scriptKeys.hasMoreElements();) {
    String scriptKey = (String) scriptKeys.nextElement();
    sb.append(scriptSet.get(scriptKey));
return sb.toString();
SetdifferentKeys(Properties p1, Properties p2)
Compare two Properties, return the set of keys whose values differ, including keys that don't exist in one or the other Properties).
if (p1 == null) {
    if (p2 == null) {
        return null;
    } else {
        return p2.keySet();
} else if (p2 == null) {
    return p1.keySet();
...
booleanequalProps(Properties p1, Properties p2)
Compare two Properties for equality (same set of properties with same (.equals) values.
if (p1 == null || p2 == null || p1.size() != p2.size()) {
    return false;
Enumeration en = p1.keys();
while (en.hasMoreElements()) {
    String k1 = (String) en.nextElement();
    if (!isKeySame(k1, p1, p2)) {
        return false;
...
ListextractFromPropertiesAsList(String prefix, Properties properties)
Extract from given properties a list of string values.
TreeMap<Integer, String> orderedMap = new TreeMap<>();
List<String> rest = new ArrayList<>();
Enumeration names = properties.propertyNames();
String prefixP = prefix + ".";
while (names.hasMoreElements()) {
    String key = (String) names.nextElement();
    if (propMatchesPrefix(prefixP, key)) {
        String index = key.substring(prefixP.length());
...
MapextractFromPropertiesAsMap(String prefix, Properties properties)
Extract part of given properties as a map.
Map<String, String> ret = new HashMap<>();
Enumeration names = properties.propertyNames();
String prefixP = prefix + ".";
while (names.hasMoreElements()) {
    String propName = (String) names.nextElement();
    if (propMatchesPrefix(prefixP, propName)) {
        String mapKey = propName.substring(prefixP.length());
        ret.put(mapKey, properties.getProperty(propName));
...
booleanisKeySame(String key, Properties p1, Properties p2)
is Key Same
Object o1 = p1.getProperty(key);
Object o2 = p2.getProperty(key, noProp);
return (o1 == o2) ||
        !((o2 == noProp || o1 == null || !o1.equals(o2)));
booleanisSupportedJVM(Map jdkProperties)
is Supported JVM
String jdkVersionString = (String) jdkProperties.get("java.version"); 
String vmNameString = (String) jdkProperties.get("java.vm.name"); 
if (jdkVersionString == null || vmNameString == null) { 
    return false;
if (isSupportedJDK(jdkVersionString)) {
    return true;
return isSupportedJDK(vmNameString);
MapmaskApplicationEnvProperties(Map environmentVariables, Set variablesToMask)
mask Application Env Properties
HashMap<String, String> masked = new HashMap<>();
for (String variableKey : environmentVariables.keySet()) {
    if (variablesToMask.contains(variableKey)) {
        masked.put(variableKey, maskEnvironmentVariable(environmentVariables.get(variableKey)));
    } else {
        masked.put(variableKey, environmentVariables.get(variableKey));
return masked;