Retrieving the Parent and Child Nodes of a Preference Node

In this section, we are going to retrieve the Parent and Child nodes of a Preference Node.

Retrieving the Parent and Child Nodes of a Preference Node

     

In this section, we are going to retrieve the Parent and Child nodes of a Preference Node. You can see in the given example that we have used Preferences.userNodeForPackage(java.lang.String.class) to get the Preference node. After that the method prefs.parent() returns the parent node. We are using the method  prefs.childrenNames() in order to get the child node. If there is no child node corresponding to the Preference node, it will return null.

Here is the code of RetrievingParentAndChild.java

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

public class RetrievingParentAndChild{
public static void main(String[]args) throws Exception{
 Preferences prefs = Preferences.userNodeForPackage(java.lang.String.class);
 Preferences node = prefs.parent();
 System.out.println("Parent Node:"+node);
 node = node.parent(); 
 String[] names = null;
  names = prefs.childrenNames();
  for (int i=0; i<names.length; i++) {
  node = prefs.node(names[i]);
  }
  System.out.println("Child Node:"+node);
}
}

Output will be displayed as:

Download Source Code:

 

Advertisements

Ads

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Retrieving the Parent and Child Nodes of a Preference Node

Posted on: January 12, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Retrieving the Parent and Child Nodes of a Preference Node  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads