Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.
Program
package com.candidjava;
import java.util.Properties;
/*
* @author : Mohan
* @description : The java.util.Properties.getProperty(String key,String defaultValue) method searches for the property with the specified key in this property list.
*/
public class PropertiesGetPropertyValue {
public static void main(String[] args) {
Properties prop = new Properties();
// add some properties
prop.put("Height", "600");
prop.put("Length", "140");
prop.put("Honesty", "true");
// get two properties and print them
System.out.println("" + prop.getProperty("Honesty", "false"));
System.out.println("" + prop.getProperty("Length", "150"));
}
}
Output
true
140
Explanation
public String getProperty(String key,String defaultValue)
Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns the default value argument if the property is not found.
Parameters:
key - the hashtable key.
defaultValue - a default value.
Returns:
the value in this property list with the specified key value.