System.clearProperty(String key)
method enables you to remove a system property. The key must not be an empty string or a null
value because it will cause the method to throw an IllegalArgumentException
or a NullPointerException
.
It will also check if a SecurityManager
exists and if you don’t have a write permission to the system property a SecurityException
is going to be thrown.
package org.kodejava.lang;
public class ClearProperty {
public static void main(String[] args) {
String key = "user.dir";
System.out.println(key + " = " + System.getProperty(key));
// The System.clearProperty() method available since Java 1.5
System.clearProperty(key);
System.out.println(key + " = " + System.getProperty(key));
}
}
The code snippet above give us the following output:
user.dir = F:\Wayan\Kodejava\kodejava-example
user.dir = null
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024