Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Util Determining If a Preference Node Contains a Specific Key

Related Tutorials


 
 

Share on Google+Share on Google+

Determining If a Preference Node Contains a Specific Key

Advertisement
This section demonstrates you to determine whether the Preference Node contains a Specific key or not.

Determining If a Preference Node Contains a Specific Key

     

This section demonstrates you to determine whether the Preference Node contains a  Specific key or not. You can see in the given example that we have create a method contain(String key) of Boolean type. This method returns true if the node contains the specified key otherwise it returns false. In order to get the Preference node, we have used Preferences.userRoot().node("/Roseindia Employees"). 

Here is the code of SpecificKey.java

import java.io.*;
import java.util.prefs.*;

public class SpecificKey{
public static boolean contain(String key) {
  Preferences node = Preferences.userRoot().node("/Roseindia Employees");
  return node.get(key, null) != null;
  }
public static void main(String[]args){
SpecificKey s=new SpecificKey();
boolean b=s.contain("EmployeeName1");
System.out.println(b);
  }
}

When you run the above program, the method search the specified key 'EmployeeName 1' in the Preference node 'Roseindia Employees'. If it finds, it will return true otherwise false. Here, the condition is true.

Download Source Code:

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 7, 2009

Related Tutorials

Discuss: Determining If a Preference Node Contains a Specific Key  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Githa
November 1, 2011
nPWPdKZUosYMHPV

I feel so much haipepr now I understand all this. Thanks!
DMCA.com