
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
Determine If a Preference Node Exists in Java
In order to determine the existence a preference node in Java, we use the nodeExists() method. The nodeExists() method returns a boolean value. It returns true when the specified preference node exists in the same tree as this node.
Declaration − The java.util.prefs.Preferences.remove() method is declared as follows −
public abstract boolean nodeExists(String pathname)throws BackingStoreException
where pathname is the path name of the node whose existence needs to be determined.
Let us see a program to determine if a preference node exists in Java −
Example
import java.util.prefs.Preferences; public class Example { public static void main(String[] args) throws Exception { boolean exist = Preferences.userRoot().nodeExists("/node"); System.out.println("Checking node existence before creation: "+exist); Preferences.userRoot().node("/node"); exist = Preferences.userRoot().nodeExists("/node"); System.out.println("Checking node existence after creation: "+exist); } }
Output
Checking node existence before creation: false Checking node existence after creation: true Dec 26, 2018 7:12:10 AM java.util.prefs.FileSystemPreferences$1 run INFO: Created user preferences directory.
Advertisements