• Java属性setProperty()方法与示例:java中的property


    java中的property

    属性类setProperty()方法 (Properties Class setProperty() method )

    setProperty() method is available in java.utilpackage.

    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:

    例:

    1. // Java program to demonstrate the example
    2. // of Object setProperty(String key_ele, String val_ele)
    3. // method of Properties
    4. import java.io.*;
    5. import java.util.*;
    6. public class SetPropertyOfProperties {
    7. public static void main(String arg[]) throws Exception {
    8. // Instantiate Properties object
    9. Properties prop = new Properties();
    10. prop.put("10", "C");
    11. prop.put("20", "C++");
    12. prop.put("30", "JAVA");
    13. prop.put("40", "PHP");
    14. prop.put("50", "SFDC");
    15. // By using setProperty() method is to
    16. // replace the old value for the given
    17. // key if exists with the given new value
    18. Object ob = prop.setProperty("20", "OOPS");
    19. // Display old value returned for the
    20. // given key element
    21. System.out.println("prop.setProperty(20,OOPS): " + ob);
    22. // Display updated list
    23. prop.list(System.out);
    24. }
    25. }

    Output

    输出量

    1. prop.setProperty(20,OOPS): C++
    2. -- listing properties --
    3. 50=SFDC
    4. 40=PHP
    5. 30=JAVA
    6. 20=OOPS
    7. 10=C
  • 相关阅读:
    canvas绘制马路和屏幕
    【零基础学QT】第四章 控件学习方法,问卷调查小界面
    【个人成长】高效能人士的七个习惯
    python使用websocket服务传输数据的例子,可以保持长连接
    解决typescript报错=》不能将类型“undefined”分配给类型“boolean”
    经过一个多月的等待我有幸成为Spring相关项目的Contributor
    如何在三星手机上截屏?每一款三星手机的每一种方法,包括S23
    Bigkey问题的解决思路与方式探索
    Spring Cloud Kubernetes:在Kubernetes中部署和管理微服务
    java list set 特性
  • 原文地址:https://blog.csdn.net/liuliuhelingdao/article/details/127544620