Getting preferences values

suggest change

A Preferences node stores each value as text under one key. The typed getters are String, boolean, byte[], double, float, int, and long. Every getter takes a default, used when the key is absent or the stored text is not valid for that type. getClass() below is the instance method, so this belongs in an instance method. A static method can pass a class literal, such as MyClass.class.

Preferences preferences = Preferences.userNodeForPackage(getClass());

String someString = preferences.get("someKey", "this is the default value");
boolean someBoolean = preferences.getBoolean("someKey", true);
byte[] someByteArray = preferences.getByteArray("someKey", new byte[0]);
double someDouble = preferences.getDouble("someKey", 887284.4d);
float someFloat = preferences.getFloat("someKey", 38723.3f);
int someInt = preferences.getInt("someKey", 13232);
long someLong = preferences.getLong("someKey", 2827637868234L);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents