Java.lang.System.clearProperty() Method

Advertisements


Description

The java.lang.System.clearProperty() method removes the system property indicated by the specified key.

Declaration

Following is the declaration for java.lang.System.clearProperty() method

public static String clearProperty(String key)

Parameters

  • key -- This is the name of the system property to be removed.

Return Value

This method returns the previous string value of the system property, or null if there was no property with that key.

Exception

  • SecurityException -- if a security manager exists and its checkPropertyAccess method doesn't allow access to the specified system property.

  • NullPointerException -- if key is null.

  • IllegalArgumentException -- if key is empty.

Example

The following example shows the usage of java.lang.System.clearProperty() method.

package com.tutorialspoint;

import java.lang.*;

public class SystemDemo {

   public static void main(String[] args) {

     // returns the previous string value of the system property
     String s = System.clearProperty("java.class.path");

     // sets the system property
     System.setProperty("user.dir", "C:/tutorialspoint/java");

     // gets the system property after changes done by setProperty
     System.out.println(System.getProperty("user.dir"));
   }
} 

Let us compile and run the above program, this will produce the following result:

C:/tutorialspoint/java



Advertisements
Advertisements