admin管理员组文章数量:1794759
Java属性setProperty()方法与示例
属性类setProperty()方法 (Properties Class setProperty() method)
setProperty() method is available in Java.util package.
setProperty()方法在java.util包中可用。
setProperty() method is used to set the given value element (val_ele) associated with the given key element (key_ele) when no value element associate previously otherwise it replaces the old value with the given value for the given key of this Properties.
setProperty()方法用于设置与给定键元素(key_ele)关联的给定值元素(val_ele),前提是之前没有关联的值元素,否则它将用此属性的给定键的给定值替换旧值。
setProperty() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
setProperty()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消。
setProperty() method does not throw an exception at the time of setting the property.
setProperty()方法在设置属性时不会引发异常。
Syntax:
句法:
public Object setProperty(String key_ele, String val_ele);Parameter(s):
参数:
String key_ele – represents the key element at which the value is to be set.
字符串key_ele –表示要在其上设置值的键元素。
String val_ele – represents the value element for the given key.
字符串val_ele –表示给定键的value元素。
Return value:
返回值:
The return type of the method is Object, it returns the old value linked with the given key if exists otherwise it returns null.
方法的返回类型为Object ,如果存在则返回与给定键链接的旧值,否则返回null。
Example:
例:
// Java program to demonstrate the example // of Object setProperty(String key_ele, String val_ele) // method of Properties import java.io.*; import java.util.*; public class SetPropertyOfProperties { public static void main(String arg[]) throws Exception { // Instantiate Properties object Properties prop = new Properties(); prop.put("10", "C"); prop.put("20", "C++"); prop.put("30", "JAVA"); prop.put("40", "PHP"); prop.put("50", "SFDC"); // By using setProperty() method is to // replace the old value for the given // key if exists with the given new value Object ob = prop.setProperty("20", "OOPS"); // Display old value returned for the // given key element System.out.println("prop.setProperty(20,OOPS): " + ob); // Display updated list prop.list(System.out); } }Output
输出量
prop.setProperty(20,OOPS): C++ -- listing properties -- 50=SFDC 40=PHP 30=JAVA 20=OOPS 10=C翻译自: www.includehelp/java/properties-setproperty-method-with-example.aspx
本文标签: 示例属性方法javasetProperty
版权声明:本文标题:Java属性setProperty()方法与示例 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686922724a118621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论