Solved Is it possible to get a hash map from a config file?

Discussion in 'Plugin Development' started by ZP18, Feb 6, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    ZP18

    Hi I would like to know if you can get a hash map from a config file, the config file would look something like this:

    Code:
    heading:
      key1: value1
      key2: value2
      key3: value3
    and the hashmap would be: Key: key1/key2/key3 and the Value: value1/value2/value3

    Is it possible to do this? I would like to know because I have an idea.

    Thank you for any help!
     
  2. Offline

    Lightspeed

    I also want to know for my problem to see what im actully doing :\
     
  3. Offline

    SuperOriginal

    Loop through the keys in the ConfigurationSection 'heads', and them to the hashmap with their respective values.
     
  4. Offline

    ZP18

    oh that makes sense!
    Code:java
    1. HashMap<String, String> keysWithValues = new HashMap<String, String>();
    2. Object[] keys = config.getConfigurationSection("heading").getKeys(false).toArray();
    3. for(int a = 0; a < keys.length; a++) {
    4. String key = keys[a].toString();
    5. String value = config.getString("heading." + key);
    6. keysWithValues.put(key, value);
    7. }


    EDIT: I would normally use:
    Code:java
    1. int i = 0
    but it stuffs up with the italic stuff
     
  5. Offline

    Darkpicasa

    I sort of disagree with this. I'd use the serializable interface.
     
    1Rogue likes this.
  6. Offline

    ZP18

    How would you achieve this?
     
  7. Offline

    Darkpicasa

    There's a ConfigurationSerializable interface, or something like that.
     
  8. Offline

    1Rogue

    Additionally ConfigurationSections are Maps.
     
    Darkpicasa likes this.
Thread Status:
Not open for further replies.

Share This Page