
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove Preference from a Preference Node in Java
In order to remove a preference from a preference node in Java, we use the remove() method. The remove method() removes all the values associated with the specified key in the preference node.
Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −
public abstract void remove (String key)
where key is the key whose preference is to be removed
The remove methods throws the following exceptions −
NullPointerException | This exception occurs when the key is null |
IllegalStateException | This exception is thrown when the ancestor node is removed by the removeNode() method. |
Let us see a program to remove the preference from a preference node −
Example
import java.util.prefs.Preferences; public class Example { public static void main(String[] args) throws Exception { // obtains the user preference node for java.lang Preferences pre = Preferences.userNodeForPackage(String.class); // Remove a preference in the node final String name = "name"; pre.remove(name); } }
Output
Dec 26, 2018 6:00:21 AM java.util.prefs.FileSystemPreferences$1 run INFO: Created user preferences directory.
Advertisements