Solved Saving HashMaps

Discussion in 'Plugin Development' started by Ricecutter0, Jun 7, 2015.

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

    Ricecutter0

    Hello, I've been recently trying to work with hashmaps, and I can't seem to be able to figure out how to save a hashmap that has a key as a String (Name) and the values in in an String List. If anyone would let me know how to do so, I'd greatly appreciate it.

    Code:

    Code:java
    1. if (!conf.contains("groups")
    2. || !conf.isConfigurationSection("groups"))
    3. conf.createSection("groups");
    4. ConfigurationSection sec = conf.getConfigurationSection("groups");
    5.  
    6. Map<String, String[]> groups = new HashMap<String, String[]>();
    7.  
    8. for (String key : sec.getKeys(false)) {
    9. if (sec.isString(key))
    10. groups.put(key, sec.getString(key));
    11. }


    EDIT:
    I think I figured it out, if I'm mistake could someone please let me know. :D

    Code:java
    1. if(!conf.contains("records") || !conf.isConfigurationSection("records"))
    2. conf.createSection("records");
    3. ConfigurationSection sec = conf.getConfigurationSection("records");
    4.  
    5. Map<String, List<String>> records = new HashMap<String, List<String>>();
    6.  
    7. for(String key : sec.getKeys(false)){
    8. ArrayList<String> list = new ArrayList<String>();
    9. if(sec.isString(key))
    10. list.add(key);
    11. records.put(key, list);
    12. }
     
    Last edited: Jun 7, 2015
Thread Status:
Not open for further replies.

Share This Page