Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put.
Program
package com.candidjava;
import java.util.Properties;
/*
* @author : Mohan
* @description : The java.util.Properties.setProperty(String key,String value) method calls the Hashtable method put. Provided for parallelism with the getProperty method.
*/
public class PropertiesSetProperty {
public static void main(String[] args) {
Properties prop = new Properties();
// add some properties
prop.setProperty("vinoth", "2");
prop.put("kamal", "1");
// print the list
System.out.println("" + prop);
// change the properties
prop.setProperty("mohan", "3");
prop.setProperty("Hari", "4");
// print the list
System.out.println("" + prop);
}
}
Output
{kamal=1, vinoth=2}
{kamal=1, Hari=4, mohan=3, vinoth=2}
Explanation
public Object setProperty(String key,String value)
Calls the Hashtable method put. Provided for parallelism with the getProperty method. Enforces use of strings for property keys and values. The value returned is the result of the Hashtable call to put.
Parameters:
key - the key to be placed into this property list.
value - the value corresponding to key.
Returns:
the previous value of the specified key in this property list, or null if it did not have one.