What is the setProperties() method in Java?
Overview
In Java, setProperties() is a static method used to set the argument instance of the Properties class to current system properties. It is the opposite of getProperties() method.
Note:
java.util.Propertiesis a subclass ofHashTableclass containing key and value pairs of string type.
Syntax
static void setProperties(Properties properties)
Parameters
setProperties() takes the parameter, properties, which represents the instance of Properties class.
Return Value
It is a void method. it does not return any value.
Example
import java.lang.*;import java.util.Properties;// Edpresso class to test this methodpublic class Edpresso {public static void main(String[] args) {// Extracting current propertiesProperties property = System.getProperties();// Putting value and key of this propertyproperty.put("java.runtime.version", "Java Runtime v8.1.0");// Calling setProperties() method to set// current system thread propertiesSystem.setProperties(property);// Getting property after "java runtime version" as valueSystem.out.println(System.getProperty("java.runtime.version"));}}
Explanation
- Line 7: We call the
getProperties()method to extract current system thread’s properties type instance.
Click here to learn more about
getProperties()function and how it works.
- Line 9: We change the java runtime version to java 8.1.0.
- Line 12: We invoke the
setProperties()method to set the current system thread’s properties. - Line 14: We print the running system thread’s properties to the console.