Java.util.Properties.setProperty(String key,String value) 方法
描述
java.util.Properties.setProperty(String key,String value) 方法调用 Hashtable 方法 put。 提供与 getProperty 方法的并行性。 强制对属性键和值使用字符串。 返回的值是对 put 的 Hashtable 调用的结果。
声明
以下是 java.util.Properties.setProperty() 方法的声明
public Object setProperty(String key,String value)
参数
key − 要放入此属性列表的键。
value − key对应的值。
返回值
此方法返回此属性列表中指定键的前一个值,如果没有,则返回 null。
异常
NA
示例
下面的例子展示了 java.util.Properties.setProperty() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class PropertiesDemo {
public static void main(String[] args) {
Properties prop = new Properties();
// add some properties
prop.setProperty("Height", "200");
prop.put("Width", "1500");
// print the list
System.out.println("" + prop);
// change the properties
prop.setProperty("Width", "15");
prop.setProperty("Height", "500");
// print the list
System.out.println("" + prop);
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
{Width=1500, Height=200}
{Width=15, Height=500}

