The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.prefs  [18 examples]

e407. Determining If a Preference Node Contains a Specific Value

This 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;
    }

 Related Examples
e405. Saving and Retrieving a Preference Value
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

See also: Events    Importing and Exporting    Nodes   


© 2002 Addison-Wesley.