How to save a HashSet in a file?

Discussion in 'Plugin Development' started by Minesuchtiiii, Mar 8, 2014.

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

    Minesuchtiiii

    Hey, as the thread name says, how can I save a HashSet in a file?
    I will save it because I've got a sign and I save its location in a HashSet, and everytime I reload or restart the server I have to create the sign new so its location gets saved into the HashSet.
    So I want to save it anywhere.
    Thanks!
    - Minesuchtiiii
     
  2. Offline

    Bart

    Save
    Code:java
    1. for(Map.Entry<String, Integer> entry : yourMap.entrySet())
    2. {
    3. getConfig().set("yourMap." + entry.getKey(), entry.getValue());
    4. }


    Load
    Code:java
    1. ConfigurationSection cs = getConfig().getConfigurationSection("yourMap");
    2. //null checks
    3. for(String s : cs.getKeys(false))
    4. {
    5. yourMap.put(s, getConfig().getInt("yourMap." + s);
    6. }


    (assuming your map is string -> integer)
     
  3. Offline

    Minesuchtiiii

    Bart
    Got red lines...

    My HashSet is a HashSet<Location>();

    bump.. help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    Bart

    Oh, hashset. Sorry. You need to serialise the location into a string
     
Thread Status:
Not open for further replies.

Share This Page