Java Preference Get getBoolean(final String key, final boolean defaultValue)

Here you can find the source of getBoolean(final String key, final boolean defaultValue)

Description

Gets a boolean value from the preferences object

License

Open Source License

Parameter

Parameter Description
key the string used to save the boolean to be retrieved
defaultValue the value to be returned in case an error is encountered

Return

the stored value if possible, defaultValue otherwise

Declaration

public static boolean getBoolean(final String key, final boolean defaultValue) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.prefs.Preferences;

public class Main {
    /**/*from  w w  w . j a  va2  s  .c o  m*/
     * The preferences node to load/save from/to
     */
    private static final Preferences prefs = Preferences.userRoot().node("/edu/colostate/vchill");

    /**
     * Gets a boolean value from the preferences object
     *
     * @param key          the string used to save the boolean to be retrieved
     * @param defaultValue the value to be returned in case an error is encountered
     * @return the stored value if possible, <code>defaultValue</code> otherwise
     */
    public static boolean getBoolean(final String key, final boolean defaultValue) {
        try {
            return prefs.getBoolean(key, defaultValue);
        } catch (Exception e) {
            return defaultValue;
        }
    }
}

Related

  1. get(String key, String defaultValue)
  2. getAltNode(final String name)
  3. getCLOB(Preferences prefs, String key, String def)
  4. getClobStorage(Preferences prefs, String key)
  5. getDefault()
  6. getFloat(String key, Float def)