dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Jul 5, 2021

How to Remove a System Property in Java

In this Java programming quick code snippet, we use java.util.Vector and java.util.concurrent.CopyOnWriteArrayList package methods to remove a system property. In particular, we use the System.clearProperty() method to achieve this. Here is the Java code example showing this method at work:

*/

import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

public class RemovingSystemProperty {
	
	public static void main(String[] args) 
	{  
		RemovingSystemProperty removingSystemProperty = new RemovingSystemProperty();
		removingSystemProperty.proceed();
	}

	private void proceed()  
	{
		System.out.println("Current System property \"user.dir\": " + System.getProperty("user.dir"));
		System.clearProperty("user.dir");
		System.out.println("After using clearProperty() value of \"user.dir\": " + System.getProperty("user.dir"));
	}
}

/*

You can expect the following output when you run this code. Note, however, that your results may vary slightly depending upon your system settings:

[root@mypc]# java CopyOnWriteArrayListEx
Current System property "user.dir": /opt/dir1/java-samples
After using clearProperty() value of "user.dir": null
MS Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date