大家好,我是你的好朋友思创斯。今天说一说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);
是否还在为ide开发工具频繁失效而烦恼,来吧关注以下公众号获取最新激活方式。亲测可用!
【正版授权,激活自己账号】:
【官方授权 正版激活】:
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
翻译自:
文章由思创斯整理,转载请注明出处:https://ispacesoft.com/141554.html