 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
 