Java Utililty Methods Properties Get

List of utility methods to do Properties Get

Description

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

Method

PropertiesgetLocalizedProperties(String[] propertyKeys, Properties properties)
get Localized Properties
Properties localizedProperties = new Properties();
for (int i = 0; i < propertyKeys.length; i++) {
    String key = propertyKeys[i];
    if (key != null) {
        String localizedValue = properties.getProperty(key);
        if (localizedValue != null)
            localizedProperties.put(key, localizedValue);
return localizedProperties;
longgetLong(Properties props, String string, long defaultV)
get Long
if (props.containsKey(string)) {
    return Long.valueOf(props.getProperty(string));
return defaultV;
MapgetNestedProperties(String prefix, Properties properties)
get Nested Properties
Map result = new HashMap();
Iterator it = properties.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry entry = (Map.Entry) it.next();
    String name = (String) entry.getKey();
    String value = (String) entry.getValue();
    result.put(prefix + '.' + name, value);
return result;
ObjectgetProp(Properties props, String name)
Get the value of the specified property.
Object val = props.get(name);
if (val != null) {
    return val;
} else {
    return props.getProperty(name);
MapgetPropertiesForBloomFilter(int requiredFieldsSize, int matchKeySize)
get Properties For Bloom Filter
Map<String, String> properties = new HashMap<String, String>();
double bestIOSortRecordPercent = 16.0 / (16.0 + 8 + requiredFieldsSize + matchKeySize);
bestIOSortRecordPercent = Math.max(Math.round(bestIOSortRecordPercent * 100) / 100.0, 0.01);
properties.put("io.sort.record.percent", Double.toString(bestIOSortRecordPercent));
return properties;
PropertiesgetPropertiesWithPrefix(Properties pro, String prefix)
get Properties With Prefix
Enumeration en;
Properties aux = new Properties();
en = pro.propertyNames();
for (; en.hasMoreElements();) {
    String nom = (String) en.nextElement();
    if (nom.startsWith(prefix)) {
        aux.setProperty(nom.substring(prefix.length()), pro.getProperty(nom));
return aux;
StringgetProperty(Properties properties, String context, String key, String def)
Returns the property with the given key from the given Properties .
String property = properties.getProperty(key, def);
if (property == null) {
    String msg = "[{0}] Property {1} is not set, and no default was given!"; 
    msg = MessageFormat.format(msg, context, key);
    throw new RuntimeException(msg);
return property;
StringgetProperty(Properties props, String keyword)
get Property
String rv = null;
if (props != null) {
    rv = props.getProperty(keyword);
if (rv != null) {
    if (rv.trim().isEmpty()) {
        rv = "";
} else {
    rv = "";
return rv;
StringgetProperty(Properties props, String prefix, String key)
get Property
return props.getProperty((prefix != null) ? prefix + "." + key : key);
StringgetProperty(Properties props, String propertyName)
Reads system variable (cmd option) or config file value on fail
return System.getProperty(propertyName, props.getProperty(propertyName));