![]() |
The Java Developers Almanac 1.4 |
|
e407. Determining If a Preference Node Contains a Specific ValueThis example enumerates the key/value pairs in a preference node and checks each value for a match. // Returns the key of a preference whose value matches the specified value;
// null is returned if no such key exists.
public static String containsValue(Preferences node, String value) {
try {
// Get all the keys
String[] keys = node.keys();
// Scan the keys
for (int i=0; i<keys.length; i++) {
if (value.equals(node.get(keys[i], null))) {
return keys[i];
}
}
} catch (BackingStoreException e) {
}
return null;
}
e406. Determining If a Preference Node Contains a Specific Key e408. Removing a Preference from a Preference Node e409. Getting and Setting Java Type Values in a Preference e410. Getting the Maximum Size of a Preference Key and Value
© 2002 Addison-Wesley. |