java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to clear system property?

System.clearProperty(String key) method enables you to remove a system property. The key should not be an empty string or a null value which will cause a IllegalArgumentException and a NullPointerException respectively.

It also check when a SecurityManager exists and you don't have a write permission to the system property a SecurityException is going to be thrown.

package com.javacoderanch.example.lang;

public class ClearProperty {
    public static void main(String[] args) {
        String key = "user.dir";

        // The System.clearProperty() method available in Java 1.5