Getting sub-nodes of Preferences

suggest change

Preferences objects always represent a specific node in a whole Preferences tree, kind of like this:

/userRoot
├── com
│   └── mycompany
│       └── myapp
│           ├── darkApplicationMode=true
│           ├── showExitConfirmation=false
│           └── windowMaximized=true
└── org
```
└── myorganization
    └── anotherapp
        ├── defaultFont=Helvetica
        ├── defaultSavePath=/home/matt/Documents
        └── exporting
            ├── defaultFormat=pdf
            └── openInBrowserAfterExport=false
To select the `/com/mycompany/myapp` node:

1. By convention, based on the package of a class:

package com.mycompany.myapp;

// …

// Because this class is in the com.mycompany.myapp package, the node // /com/mycompany/myapp will be returned. Preferences myApp = Preferences.userNodeForPackage(getClass());

2. By relative path:

       Preferences myApp = Preferences.userRoot().node("com/mycompany/myapp");

   Using a relative path (a path not starting with a `/`) will cause the path to be resolved relative to the parent node it is resolved on. For example, the following example will return the node of the path `/one/two/three/com/mycompany/myapp`:

Preferences prefix = Preferences.userRoot().node(“one/two/three”); Preferences myAppWithPrefix = prefix.node(“com/mycompany/myapp”); // prefix is /one/two/three // myAppWithPrefix is /one/two/three/com/mycompany/myapp

3. By absolute path:

       Preferences myApp = Preferences.userRoot().node("/com/mycompany/myapp");

   Using an absolute path on the root node will not be different from using a relative path. The difference is that, if called on a sub-node, the path will be resolved relative to the root node.

Preferences prefix = Preferences.userRoot().node(“one/two/three”); Preferences myAppWitoutPrefix = prefix.node(”/com/mycompany/myapp”); // prefix is /one/two/three // myAppWitoutPrefix is /com/mycompany/myapp

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Preferences:
* Getting sub-nodes of Preferences

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
43 Preferences
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap