Search code examples
javaobjectsettingsapplication-settings

Aternative to storing settings in hashmap of the object data type in java?


Alternative to storing settings in a hashmap of object in java?

private static HashMap<String, Object> settingsMap = new HashMap();

public static void addSetting(String name, Object value) {
    settingsMap.put(name, value);
}

public static Object getSetting(String name) {
     return settingsMap.get(name);
}

public static void setSetting(String name, Object value) {
    settingsMap.replace(name, setting);
}

Solution

  • The Properties class would be a good option for that. But it stores all values as Strings. If that is feasible in your scenario, you also get the easy feature to save and load those properties from/to a file via single method calls.