Preferences: getInt(String key, int def)
import java.util.prefs.Preferences;
public class Main {
public static void main(String[] argv) throws Exception {
Preferences prefs = Preferences.userNodeForPackage(Main.class);
// Preference key name
final String PREF_NAME = "name_of_preference";
// Save
prefs.put(PREF_NAME, "a string"); // String
prefs.putBoolean(PREF_NAME, true); // boolean
prefs.putInt(PREF_NAME, 123); // int
prefs.putLong(PREF_NAME, 123L); // long
prefs.putFloat(PREF_NAME, 12.3F); // float
prefs.putDouble(PREF_NAME, 12.3); // double
byte[] bytes = new byte[1024];
prefs.putByteArray(PREF_NAME, bytes); // byte[]
// Retrieve
String s = prefs.get(PREF_NAME, "a string"); // String
boolean b = prefs.getBoolean(PREF_NAME, true); // boolean
int i = prefs.getInt(PREF_NAME, 123); // int
long l = prefs.getLong(PREF_NAME, 123L); // long
float f = prefs.getFloat(PREF_NAME, 12.3F); // float
double d = prefs.getDouble(PREF_NAME, 12.3); // double
bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[]
}
}
Related examples in the same category
1. | Preferences.MAX_KEY_LENGTH | | |
2. | Preferences.MAX_VALUE_LENGTH | | |
3. | Preferences: absolutePath() | | |
4. | Preferences: addPreferenceChangeListener(PreferenceChangeListener pcl) | | |
5. | Preferences: exportNode(OutputStream os) | | |
6. | Preferences: exportSubtree(OutputStream os) | | |
7. | Preferences: get(String key, String def) | | |
8. | Preferences: getBoolean(String key, boolean def) | | |
9. | Preferences: getByteArray(String key, byte[] def) | | |
10. | Preferences: getDouble(String key, double def) | | |
11. | Preferences: getFloat(String key, float def) | | |
12. | Preferences: getLong(String key, long def) | | |
13. | Preferences: importPreferences(InputStream is) | | |
14. | Preferences: keys() | | |
15. | Preferences: name() | | |
16. | Preferences: node(String pathName) | | |
17. | Preferences: nodeExists(String pathName) | | |
18. | Preferences: parent() | | |
19. | Preferences: put(String key, String value) | | |
20. | Preferences: putBoolean(String key, boolean value) | | |
21. | Preferences: putByteArray(String key, byte[] value) | | |
22. | Preferences: putDouble(String key, double value) | | |
23. | Preferences: putFloat(String key, float value) | | |
24. | Preferences: putLong(String key, long value) | | |
25. | Preferences: remove(String key) | | |
26. | Preferences: removeNode() | | |
27. | Preferences: systemRoot() | | |
28. | Preferences: userNodeForPackage(Class c) | | |
29. | Preferences: userRoot() | | |