

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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.
- Related Questions & Answers
- Removing a Preference from a Preference Node in Java
- Determine if file or directory exists in Java
- Check if a file exists in Java
- How to determine whether a field exists in MongoDB?
- Determine if a String is a legal Java Identifier
- Check if a particular element exists in Java LinkedHashSet
- Check if a particular key exists in Java LinkedHashMap
- Check if a particular value exists in Java LinkedHashMap
- Check if a particular value exists in Java TreeSet
- Check if a given key exists in Java HashMap
- Check if a File exists in C#
- Java Program to check if a given value exists in a HashMap
- Java Program to check if a particular key exists in TreeMap
- Java Program to check if a particular value exists in TreeMap
- Java Program to check if a particular element exists in HashSet
Advertisements