Determining If a Preference Node Contains a Specific Value - Java Native OS

Java examples for Native OS:Preference

Description

Determining If a Preference Node Contains a Specific Value

Demo Code

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

public class Main {
  public static String containsValue(Preferences node, String value) {
    try {/*  www .  jav a 2  s.c o  m*/
      // 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 Tutorials