Java Properties.setProperty(String key, String value)

Syntax

Properties.setProperty(String key, String value) has the following syntax.

public Object setProperty(String key,   String value)

Example

In the following code shows how to use Properties.setProperty(String key, String value) method.


import java.util.Properties;
//from w  ww.j  a v a2  s.  c  o m
public class Main {

  public static void main(String[] args) throws Exception {
    Properties prop = new Properties();

    prop.setProperty("Chapter Count", "200");
    prop.put("Tutorial Count", "1500");
    prop.put("tutorial", "java2s.com");
    
    // print the list
    System.out.println(prop);

    // change the properties
    prop.setProperty("Tutorial Count", "15");
    prop.setProperty("Chapter Count", "500");

    // print the list
    System.out.println(prop);
  }
}

The code above generates the following result.