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.example.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 in Java 1.5
System.clearProperty(key);
System.out.println(key + " = " + System.getProperty(key));
}
}
The code snippet above give us the following output:
user.dir = /Users/wsaryada/kodejava/src/kodejava-project user.dir = null
Wayan
Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me, buy me ☕ or 🍵
Latest posts by Wayan (see all)
- How do I set the default Java (JDK) version on Mac OS X? - November 14, 2017
- A User Interface is Like a Joke - November 10, 2017
- How do I pass password to sudo commands? - October 17, 2017