Home Java Example Java Util Retrieving the Parent and Child Nodes of a Preference Node
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Retrieving the Parent and Child Nodes of a Preference Node

Advertisement
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

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 12, 2009

Related Tutorials

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com